+------------------------+----------------------------------------------------+---------------------------+---------------------+
| row_to_json(record [, | Returns the row as a JSON object. | row_to_json(row(1,'foo')) | {"f1":1,"f2":"foo"} |
| pretty_bool]) | Line feeds will be added between level-1 elements | | |
| | if pretty_bool is true. | | |
+------------------------+----------------------------------------------------+---------------------------+---------------------+
给出下一个例子:
让我从中选择一些记录
tbl
:现在使用子查询:
如您所见,两个查询都返回相同的行,那么您可以使用这两个查询来生成 JSON 结果。
dbfiddle here
正如@ypercube 所指出的,当您执行时:
你得到这个结果:
与使用相同的输出:
它是一个(命名的)复合类型。(查看有关TYPE的文档)
看看row_to_json()函数:
以一行为例:
row_to_json(row(1,'foo'))