英文:
SQL Query Where array of objects
问题
我有一个包含对象数组的字段的表格。这是字段的一个示例值:
[
{a: "test"},
{a: "testing"}
]
我试图查询数据,其中比较是在数组对象字段上进行的,类似于这样的查询:SELECT * FROM table_1 WHERE table_1.a = "test"
。我无法理解的部分是在WHERE条件上,或者这是否不可能实现?
英文:
I have a table that has a field that contains an array of objects. Here's a sample value of the field
[
{a: "test"},
{a: "testing"}
]
I'm trying to do a query data where the comparison is on the array of object fields that kinda looks like this SELECT * FROM table_1 WHERE table_1.a = "test"
. The part that I can't get is on the WHERE condition or is this not possible?
答案1
得分: 0
我已找到答案
要么是这两者之一
SELECT * FROM table_1 WHERE table_1.field @>'[{"a":"test"}]'::jsonb
或
SELECT * FROM table_1 WHERE table_1.field::text 类似于 '%("a": "test")%'
英文:
I have found an answer to this
its either of this two
SELECT * FROM table_1 WHERE table_1.field@>'[{"a":"test"}]'::jsonb
or
SELECT * FROM table_1 WHERE table_1.field::text similar to '%("a": "test")%'
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论