我有一个类似的postres表:(缩短)
id (serial) | col1 (character varying[])
----------------------------------------
1 | {'Life', 'Health', "'VA Data'"}
我正在尝试执行以下操作:
SELECT * FROM mytable WHERE 'Life' = ANY (col1)
此查询的结果为零记录。
目标是,我想要任何行,在col1数组中具有值'Life'。
我做错了什么?
答案 0 :(得分:3)
Any
should work, but what you are showing me for output for the table is not Life but 'Life'. See the examples below (1. correctly inserted data and what it looks like; 2. incorrectly inserted data and what it looks like-looks like yours; 3. all data):
testdb=# select * from test where 'Life' = ANY(col1);
id | col1
----+-------------------------
1 | {Life,Health,"VA Data"}
(1 row)
testdb=# select * from test where '''Life''' = ANY(col1);
id | col1
----+---------------------------
2 | {'Life',Health,"VA Data"}
(1 row)
testdb=# select * from test;
id | col1
----+---------------------------
1 | {Life,Health,"VA Data"}
2 | {'Life',Health,"VA Data"}