Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.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 如何将行传输到jsonb并设置键的名称?_Sql_Postgresql - Fatal编程技术网

Sql 如何将行传输到jsonb并设置键的名称?

Sql 如何将行传输到jsonb并设置键的名称?,sql,postgresql,Sql,Postgresql,我有一个具有以下字段的table person:id、名字、姓氏。 查询: 返回此结果: { "id": 1, "firstname": Alex } 如何获得结果: { "id": 1, "firstName": Alex } 在Postgres中,不带引号的标识符被折叠为小写,因此您需要使用带引号的标识符: select COALESCE(jso

我有一个具有以下字段的table person:id、名字、姓氏。
查询:

返回此结果:

  {
      "id": 1,
      "firstname": Alex
  }
如何获得结果:

  {
      "id": 1,
      "firstName": Alex
  }

在Postgres中,不带引号的标识符被折叠为小写,因此您需要使用带引号的标识符:

select COALESCE(jsonb_agg(to_jsonb(data)), '{}'::jsonb)
from (
   select id, first_name as "firstName" 
   from person
) data
select COALESCE(jsonb_agg(to_jsonb(data)), '{}'::jsonb)
from (
   select id, first_name as "firstName" 
   from person
) data