Postgres SELECT其中数组中的值 [英] Postgres SELECT where value in array

查看:86
本文介绍了Postgres SELECT其中数组中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个postres表,看起来像这样:(缩短)

I have a postres table that looks like such: (shortened)

id (serial) | col1 (character varying[])
----------------------------------------
1           | {'Life', 'Health', "'VA Data'"}

我正在尝试以下内容:

SELECT * FROM mytable WHERE 'Life' = ANY (col1)

此查询的结果是零条记录。

The results of this query, is zero records.

目标是,我要

我在做什么错了?

推荐答案

任何应该可以,但是显示给我的表输出不是Life,而是'Life'。请参见下面的示例(1.正确插入的数据及其外观; 2.错误插入的数据及其外观-看起来像您的外观; 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"}

这篇关于Postgres SELECT其中数组中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆