将列值插入到postgres中的hstore数据类型中

问题描述 投票:0回答:1

我在postgres中有一个表,其中有这三列id_0,turnr和标签。标签列的数据类型为hstore。当前我正在使用此查询,该查询不起作用

INSERT INTO relation_15_02_2020 (tags)
VALUES
   (
   '
       "type"=>"restriction",
       "restriction"=>"(select distinct(turnr) from relation_15_02_2020  ) "
       '
   );

我如何添加

"type"=>"restriction",
"restriction"=>" turnr value for respective id  

id_0 = 1标签的期望输出

 {"type"=>"restriction","restriction"=>"NoRightTurn"}

enter image description here

postgresql hstore
1个回答
0
投票

您要更新行,而不要插入新行:

update relation_15_02_2020 
  set tags = hstore(array['type', 'restriction'], array['restriction', turnr])
where id_0 = 1;

或者]

update relation_15_02_2020 
  set tags = hstore('type', 'restriction')||hstore('restriction', turnr)
where id_0 = 1;
© www.soinside.com 2019 - 2024. All rights reserved.