首页 > 解决方案 > 需要在 psql 中以特定格式输出

问题描述

认为:-

subh=# select 'test123';
          ?column?
-------------------------------------
         test123

subh=# select obj_description('test123'::regclass);
  obj_description
--------------------
 this is my table

我正在运行此查询:-

subh=# select 'test123' || ' ' || obj_description('test123'::regclass) as test;
             test
 -------------------------------
  test123 this is my table

实际上我希望输出如下: -

            test
-------------------------------
  test123 'this is my table'

标签: sqlconcatgreenplum

解决方案


利用quote_literal

此函数在给定字符串/数字的前后添加单引号。在这里阅读。

subh=# select 'test123' || ' ' || quote_literal(obj_description('test123'::regclass)) as test;

推荐阅读