[英]Postgres query to get array from inside one of the properties of a JSON object
So basically the column(col1) looks like this: 所以基本上,column(col1)看起来像这样:
{"property1": [1, 2], "property2": 3}
So I want to get that array of property1 so that I can check if another number is in that array. 因此,我想获取该property1数组,以便可以检查该数组中是否还有另一个数字。
The following is what I want to do: 以下是我要执行的操作:
SELECT *
FROM table
WHERE 1 = ANY((col1 ->> 'property1'));
Or something to that effect. 或类似的东西。 The problem is that query brings it back as text, and no matter how I try, it does not want to become an array.
问题是查询将其作为文本带回,并且无论我如何尝试,它都不想成为数组。
Even tried stuff like this: 甚至尝试过这样的东西:
SELECT *
FROM table
WHERE 1 = ANY((col1 -> 'property1')::int[]);//Says jsonb cant be cast to integer
I tried multiple other things and couldn't get it working. 我尝试了其他多种方法,但无法正常工作。
SELECT *
FROM table
WHERE '1'::jsonb <@ (col1->'property1')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.