根据postgres文档,您可以将键添加到hstore列,如下所示:
UPDATE tab SET h = h || ('c' => '3');
Run Code Online (Sandbox Code Playgroud)
但它似乎只有在hstore字段不为空时才有效.例如:
postgres=# create table htest (t text, h hstore);
CREATE TABLE
postgres=# insert into htest (t) VALUES ('key');
INSERT 0 1
postgres=# update htest set h = h || ('foo'=>'bar') where t='key';
UPDATE 1
postgres=# select * from htest;
t | h
-----+---
key |
(1 row)
Run Code Online (Sandbox Code Playgroud)
更新成功,但hstore未更新.然而:
postgres=# update htest set h = ('foo'=>'bar') where t='key';
UPDATE 1
postgres=# select * from htest;
t | h
-----+--------------
key …Run Code Online (Sandbox Code Playgroud) postgresql ×1