PostgreSQL:使用jsonb_build_object时如何消除输出的函数名列名?
PostgreSQL中移除jsonb_build_object函数名作为列名的方法
你只需要给jsonb_build_object生成的结果指定一个列别名即可解决这个问题,PostgreSQL默认会把整个函数表达式作为列名,自定义别名就能替换掉它。
有两种常用写法:
- 使用
AS关键字明确指定别名:
select jsonb_build_object( 'country_name', country_name, 'country_code', country_code, 'currency_code', currency_code ) AS country_info from table;
- 省略
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
相关产品推荐
相关产品推荐

