json_populate_record()

一个用于将 JSON 对象扩展为行的函数

json_populate_record() 是一个系统函数,用于将顶层的 JSON 对象扩展为具有指定基类型的复合类型的一行。

json_populate_record() 添加于 PostgreSQL 9.3

用法

json_populate_record ( base anyelement, from_json json ) → anyelement

有关详细规范,请参阅 PostgreSQL 文档

变更历史

示例

要获得 json_populate_record() 的独立示例,有必要创建一个自定义类型

postgres=# CREATE TYPE keyrec AS (key INT, val TEXT);
CREATE TYPE

该类型从 json_populate_record() 如下引用

postgres=# SELECT * FROM json_populate_record(
               NULL::keyrec,
               '{"key": 1,"val": "foo"}'
           );
 key | val 
-----+-----
   1 | foo
(1 row)

字段与任何输出列都不对应的那些值将被忽略

postgres=# SELECT * FROM json_populate_record(
               NULL::keyrec,
               '{"key": 1,"val": "foo", "bar": "baz"}'
           ); 
 key | val 
-----+-----
   1 | foo
(1 row)

分类

JSON, 系统函数

另请参阅

json_populate_recordset(), jsonb_populate_record(), jsonb_populate_record_valid()

反馈

提交任何关于“json_populate_record()”的评论、建议或更正请在此处 提交