Postgres SELECT数组中的where值



我有一个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"}

最新更新