Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 查询json数组中的所有对象_Sql_Json_Postgresql - Fatal编程技术网

Sql 查询json数组中的所有对象

Sql 查询json数组中的所有对象,sql,json,postgresql,Sql,Json,Postgresql,我希望对数据库中的一列进行查询,但该列的类型为jsonb。这是结构的一个示例: select json_column->>'left' from schema.table; [{"id": 123, "name": "Joe"}, {"id": 456, "name": "Jane"}, {"id": 789, "name&q

我希望对数据库中的一列进行查询,但该列的类型为jsonb。这是结构的一个示例:

select json_column->>'left' from schema.table;

[{"id": 123, "name": "Joe"}, 
 {"id": 456, "name": "Jane"}, 
 {"id": 789, "name": "John"}, 
 {"id": 159, "name": "Jess"}]
本质上,我只是想从中返回所有的name字段,但我想不出来

我试过了

select json_column->'left'->>'name' from schema.table
但这只会返回一个空值

我也尝试过:

select elem->>'name'
from schema.table m,
jsonb_array_elements(json_column->'left') elem;
但这给了我:

ERROR:  cannot extract elements from an object

当我插入where子句时,这似乎有效,例如:

select elem->>'name'
from schema.table m,
jsonb_array_elements(json_column->'left') elem
where m.id = 1;