sql - 插入到从 psql 中的不同表中选择的 jsonb 列中
问题描述
插入从 psql 中的不同表中选择的 jsonb 列。我想要jsonb插入
{"name": "myname" ,"email": "test@gmail.com"}
我想做一些类似“name”的事情:“myname”常量值和电子邮件是从另一个表中选择的
insert into test1 (column1) select {"name": "myname" ,"email": email}
解决方案
只需使用 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;
推荐阅读
- python - 使用正则表达式匹配最后一次出现
- azure - Azure Blob 错误:指定的 Blob 不存在,但 Blob 存在
- reactjs - ReactJS Firebase 检索批量上传图像的 URL
- python-3.x - fetchall() 的结果是否有一些 next() 可迭代
- kubernetes - 使用客户拥有的密钥加密 kubernetes pvc 存储
- jquery-select2 - 如果我们动态附加新选项,选择 2 不起作用
- typo3 - TYPO3 bootstrap_grids - 如何修改内容元素的标题?
- reactjs - 使用 react-hooks-testing-library 测试自定义钩子
- java - 为什么它说它已经使用构造函数定义了?
- javascript - 单击按钮时从选择控件中隐藏选项