需要在psql中以特定格式输出

时间:2018-08-27 11:50:53

标签: sql concat greenplum

假设:-

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'

2 个答案:

答案 0 :(得分:0)

使用quote_literal

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

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

答案 1 :(得分:-1)

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

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

\'将用于添加报价