我试图从存储在 Postgres 数据库中的另一个数组中的 Json 数组中读取元素,但我的结果集始终为空。我的桌子如下所示:
表中的 Json 示例:
{"test":{"accountName":"OS1U","details":[{"status":{"statusCode":"Test Ready","modifiedDate":"2023-07-31T14:53:49Z"},"products":[{"productId":"0001","productName":"2GB","productDescription":"testproduct12"},{"productId":"0005","productName":"2GB","productDescription":"testproduct12"}]}]}}
这里我的要求是从具有productId(0001,0005)的表中获取所有id。我尝试了下面的sql:
SELECT x.id
FROM (
SELECT json_array_elements("json" -> 'test' -> 'details'->'products') AS products,"id"
FROM table_test b
) x
WHERE x.products ->> 'productId' in ('0001','0005');
但它总是返回空数据集。谁能指导我纠正上述陈述