繁体   English   中英

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

[英]Need the output in specific format in 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'

使用quote_literal

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

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

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

\\'将用于添加报价

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM