jsonb应用 select from tjsonb; id fjsonb + 1 {"col": "pgxz", "col1": 1, "col2": "teledb"} 2 {"col1": 1, "col2": "teledb"} 3 {"col1": 1, "col2": "teledbupdate"} (3 rows) teledb update tjsonb set fjsonb jsonbset( fjsonb , '{col2}' , '"pgxz"' , false ) where id3; UPDATE 1 teledb select from tjsonb; id fjsonb + 1 {"col": "pgxz", "col1": 1, "col2": "teledb"} 2 {"col1": 1, "col2": "teledb"} 3 {"col1": 1, "col2": "pgxz"} (3 rows) jsonb 函数应用 jsonbeach() 将 json 对象转变键和值 teledb select fjsonb from tjsonb where id1; fjsonb {"col": "pgxz", "col1": 1, "col2": "teledb"} (1 row) teledb select from jsonbeach((select fjsonb from tjsonb where id1)); key value + col "pgxz" col1 1 col2 "teledb" (3 rows) jsonbeachtext() 将 json 对象转变文本类型的键和值 teledb select from jsonbeachtext((select fjsonb from tjsonb where id1)); key value + col pgxz col1 1 col2 teledb (3 rows) rowtojson() 将一行记录变成一个json对象 teledb create table t1(id int, name varchar); CREATE TABLE teledb insert into t1 values(1,'teledb'),(2,'pgxc'); COPY 2 teledb select from t1; id name + 1 teledb 2 pgxc (2 rows) teledb select rowtojson(t1) from t1; rowtojson {"id":1,"name":"teledb"} {"id":2,"name":"pgxc"} (2 rows)