row_to_json()将一行记录变成一个json对象
最近更新时间: 2025-02-18 16:02:00
postgres=# \d+ tbase
Table "public.tbase"
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
----------+---------+-----------+----------+---------+----------+--------------+-------------
id | integer | | not null | | plain | |
nickname | text | | | | extended | |
Indexes:
"tbase_pkey" PRIMARY KEY, btree (id)
Distribute By: SHARD(id)
Location Nodes: ALL DATANODES
postgres=# select * from tbase;
id | nickname
----+----------
1 | TDSQL PG
2 | pgxz
(2 rows)
postgres=# select row_to_json(tbase) from tbase;
row_to_json
-----------------------------
{"id":1,"nickname":"TDSQL PG"}
{"id":2,"nickname":"pgxz"}
(2 rows)