lateral

Query for element of array in JSON column

喜你入骨 提交于 2019-11-26 08:16:16
问题 Recently upgraded to using PostgreSQL 9.3.1 to leverage the JSONfunctionalities. In my table I have a json type column that has a structure like this: { \"id\": \"123\", \"name\": \"foo\", \"emails\":[ { \"id\": \"123\", \"address\": \"somethinghere\" }, { \"id\": \"456\", \"address\": \"soemthing\" } ] } This is just dummy data for the purpose of the question. Is it possible to query for a specific item in the emails array based on the id? Pretty much: \"return email where id=123)\"? 回答1:

Query for array elements inside JSON type

女生的网名这么多〃 提交于 2019-11-26 06:49:40
I'm trying to test out the json type in PostgreSQL 9.3. I have a json column called data in a table called reports . The JSON looks something like this: { "objects": [ {"src":"foo.png"}, {"src":"bar.png"} ], "background":"background.png" } I would like to query the table for all reports that match the 'src' value in the 'objects' array. For example, is it possible to query the DB for all reports that match 'src' = 'foo.png' ? I successfully wrote a query that can match the "background" : SELECT data AS data FROM reports where data->>'background' = 'background.png' But since "objects" has an

Query for array elements inside JSON type

房东的猫 提交于 2019-11-26 01:51:39
问题 I\'m trying to test out the json type in PostgreSQL 9.3. I have a json column called data in a table called reports . The JSON looks something like this: { \"objects\": [ {\"src\":\"foo.png\"}, {\"src\":\"bar.png\"} ], \"background\":\"background.png\" } I would like to query the table for all reports that match the \'src\' value in the \'objects\' array. For example, is it possible to query the DB for all reports that match \'src\' = \'foo.png\' ? I successfully wrote a query that can match