sql - 如何查询在 postgres 中以字符串形式存在的数组?

标签 sql postgresql postgresql-9.5

我有一个名为 table 的表,其中包含名为 column 的列,数据类型为 text,其值类似于 '["1","2"]'.

我需要获取所有以“1”作为元素之一的记录。

select * 
from table 
where column.....?

where子句应该怎么写?

最佳答案

只需使用LIKE。保留双引号以传递 1,但避免包含该数字的其他数字。

select * 
from table 
where column like '%"1"%' 

关于sql - 如何查询在 postgres 中以字符串形式存在的数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58008972/

相关文章:

postgresql - 如何执行 PostgreSQL 交叉表查询列中缺少值

arrays - 检查表中 varchar[] 和 varchar[][] 列的约束

sql - 为什么 Rails 在使用具有关联的作用域时会生成重复的 SQL 条件?

sql - 测试正常时正则表达式无法正常工作

sql - 匿名复合类型的输入未实现 - Postgres

python - python中两个列表的比较

postgresql - 我如何在 PostgreSQL 中创建 "lo datatypes"

sql - Qt 中的持久化类

sql - 查询 'get the records from the actual month' 没有得到比当前日期大的记录

postgresql - 如何在 Kubernetes 中使用 Aws EBS 挂载 postgresql 卷