数据仓库服务 GAUSSDB(DWS)-JSON/JSONB函数:to_json(anyelement)

时间:2024-11-28 17:39:01

to_json(anyelement)

描述:把参数转换为json。

返回类型:json

示例:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
SELECT to_json('Fred said "Hi."'::text);
       to_json
---------------------
 "Fred said \"Hi.\""
(1 row)
——将列存表json_tbl_2转换为json
postgres=# SELECT * FROM json_tbl_2;
  a |  b 
 ---+-----
  1 | aaa 
  1 | bbb 
  2 | ccc  
  2 | ddd 
 (4 rows) 
postgres=# SELECT to_json(t.*) FROM json_tbl_2 t;
      to_json
-------------------
 {"a":1,"b":"bbb"}
 {"a":2,"b":"ddd"}
 {"a":1,"b":"aaa"}
 {"a":2,"b":"ccc"}
(4 rows)
support.huaweicloud.com/sqlreference-830-dws/dws_06_0356.html