jsonb应用 本文介绍天翼云TeleDB数据库jsonb应用。 创建jsonb类型字段表 plaintext teledb create table tjsonb(id int,fjsonb jsonb); CREATE TABLE 插入数据 plaintext teledb insert into tjsonb values(1,'{"col1":1,"col2":"teledb"}'); INSERT 0 1 teledb insert into tjsonb values(2,'{"col1":1,"col2":"teledb","col3":"pgxz"}'); INSERT 0 1 teledb select from tjsonb; id fjsonb + 1 {"col1": 1, "col2": "teledb"} 2 {"col1": 1, "col2": "teledb", "col3": "pgxz"} (2 rows) jsonb插入时会移除重复的键,如下所示。 plaintext teledb insert into tjsonb values(3,'{"col1":1,"col2":"teledb","col2":"pgxz"}'); INSERT 0 1 teledb select from tjsonb; id fjsonb + 1 {"col1": 1, "col2": "teledb"} 2 {"col1": 1, "col2": "teledb", "col3": "pgxz"} 3 {"col1": 1, "col2": "pgxz"} (3 rows) 更新数据 增加元素。 plaintext teledb update tjsonb set fjsonb fjsonb '{"col3":"pgxz"}'::jsonb where id1; UPDATE 1 teledb select from tjsonb; id fjsonb + 2 {"col1": 1, "col2": "teledb", "col3": "pgxz"} 1 {"col1": 1, "col2": "teledb", "col3": "pgxz"} 3 {"col1": 1, "col2": "pgxz"} (3 rows) 更新原来的元素。 plaintext teledb