PSQL不正常功能无法按预期工作

时间:2017-06-08 17:18:38

标签: sql postgresql select unnest

我尝试了this post的解决方案,但我仍然收到错误。

查询:

SELECT unnest(team)
FROM table_of_teams
WHERE team LIKE '%akg%';

错误:

ERROR:  operator does not exist: character varying[] ~~ unknown
LINE 5: WHERE team LIKE '%akg%'
                   ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.

表格结构:

                            Table "public.table_of_teams"
       Column       |            Type             |                   Modifiers                     
--------------------+-----------------------------+-------------------------------------------------
 teamid             | integer                     | not null default nextval('team_seq'::regclass)
 index              | integer                     | 
 name               | character varying           | 
 grouping           | character varying           | 
 hour_of_day        | integer[]                   | 
 day_of_week        | integer[]                   | 
 team               | character varying[]         | 

1 个答案:

答案 0 :(得分:1)

如果我理解正确并且您想要提取符合给定条件的团队,您可以将unnest调用放在子查询中并在周围查询中应用条件:

SELECT single_team
FROM   (SELECT unnest(team) single_team
        FROM table_of_teams) t
WHERE single_team LIKE '%akg%';