Questions tagged «lateral»

3
查询JSON类型内的数组元素
我正在尝试测试jsonPostgreSQL 9.3中的类型。 我在json名为data的表中有一个列reports。JSON看起来像这样: { "objects": [ {"src":"foo.png"}, {"src":"bar.png"} ], "background":"background.png" } 我想查询表中所有与“对象”数组中“ src”值匹配的报告。例如,是否可以在数据库中查询所有匹配的报告'src' = 'foo.png'?我成功地写了一个查询,可以匹配"background": SELECT data AS data FROM reports where data->>'background' = 'background.png' 但是由于"objects"具有一组值,所以我似乎无法编写出有效的东西。是否可以在数据库中查询所有匹配的报告'src' = 'foo.png'?我已经查看了这些来源,但仍然无法了解: http://www.postgresql.org/docs/9.3/static/functions-json.html 如何使用新的PostgreSQL JSON数据类型内的字段进行查询? http://michael.otacoo.com/postgresql-2/postgres-9-3-feature-highlight-json-operators/ 我也尝试过类似的方法,但无济于事: SELECT json_array_elements(data->'objects') AS data from reports WHERE data->>'src' = 'foo.png'; 我不是SQL专家,所以我不知道我做错了什么。
118 sql  json  postgresql  jsonb  lateral 
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.