sql - 如何为使用 jsonb_to_recordset 检索的列设置别名?
问题描述
我有包含对象数组的“电话”列。例如
[
{
"id": 8789789789,
"phone": "111111111",
"default": true,
"code": "11",
"country_code": "US"
}
]
我需要从这个数组中的一个对象中加入一些值,所以我使用 jsonb_to_recordset 和横向交叉连接
select *
from "phones" cross join lateral
jsonb_to_recordset(phone) as r(phone jsonb, country_code jsonb)
where "r.country_code" = ? and "deleted_at" is null
这里的问题是检索到的电话(来自对象)用 json 覆盖了初始电话列。如何为连接列设置别名,以便它们不会覆盖原始列?
解决方案
你可以给他们新的祝福:
select p.*,
r.phone as r_phone,
r.r_country_code as r_country_code
from "phones" p cross join lateral
jsonb_to_recordset(phone) as r(phone jsonb, country_code jsonb)
where "country_code" = ? and "deleted_at" is null
推荐阅读
- javascript - 反应:子组件中的切换功能未按预期工作
- javascript - 如何通过 JS 脚本或在 React Native 中运行 Monero CLI 命令?
- python - 无法设置 python 事件标志
- javascript - 包含链接的 div 的 Javascript dom 子项
- css - 用户向下滚动时扩展和更改导航栏
- java - 当基础 IAction 贡献项更新时刷新 IContributorManager
- html - z-index 堆叠指定之外的元素
- gps - 不同的结果来自 2 个相同的 gps 模块,在相同的位置使用相同的程序
- php - 在 PHP 中显示 MySQL 请求
- asp.net-mvc - 获取 web api 的属性值 Sharepoint 属性包