You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PostgreSQL:使用jsonb_build_object时如何消除输出的函数名列名?

PostgreSQL中移除jsonb_build_object函数名作为列名的方法

你只需要给jsonb_build_object生成的结果指定一个列别名即可解决这个问题,PostgreSQL默认会把整个函数表达式作为列名,自定义别名就能替换掉它。

有两种常用写法:

  1. 使用AS关键字明确指定别名:
select  jsonb_build_object(
                    'country_name', country_name,
                    'country_code', country_code,
                    'currency_code', currency_code
                ) AS country_info
from table;
  1. 省略AS直接写别名(PostgreSQL支持这种简化写法):
select  jsonb_build_object(
                    'country_name', country_name,
                    'country_code', country_code,
                    'currency_code', currency_code
                ) country_info
from table;

你可以把country_info换成任何你想要的列名,这样查询结果里就会显示你指定的名称,而不是函数名了。

内容的提问来源于stack exchange,提问作者Nabeel Khan Ghauri

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 22:14:52