我有一个看起来像这样的 postres 表:(缩短)
id (serial) | col1 (character varying[])
----------------------------------------
1 | {'Life', 'Health', "'VA Data'"}
我正在尝试执行以下操作:
SELECT * FROM mytable WHERE 'Life' = ANY (col1)
这个查询的结果,是零条记录。
目标是,我想要在 col1 数组中具有值“Life”的任何行。
我做错了什么?
最佳答案
Any
应该可以工作,但是您向我展示的表格输出不是 Life 而是“Life”。请参阅下面的示例(1. 正确插入的数据及其外观;2. 错误插入的数据及其外观 - 看起来像您的;3. 所有数据):
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"}
关于postgresql - Postgres SELECT 数组中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34191848/