【问题标题】:insert into a jsonb column selecting from different table in psql插入到从 psql 中的不同表中选择的 jsonb 列中
【发布时间】:2019-01-23 03:31:07
【问题描述】:

插入从 psql 中的不同表中选择的 jsonb 列。我想要像

这样的 jsonb 插入
{"name": "myname" ,"email": "test@gmail.com"}

我想做一些类似“name”的事情:“myname”常量值和电子邮件是从另一个表中选择的

insert into test1 (column1) select {"name": "myname" ,"email": email}

【问题讨论】:

    标签: sql json postgresql sql-insert


    【解决方案1】:

    只需使用 row_to_json 将选定的行转换为 json。然后根据需要转换为 jsob。

    insert into test1 (column1)
    select row_to_json(x)::jsonb from (select 'myname' as name, email from another_table) x;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-04
      • 1970-01-01
      相关资源
      最近更新 更多