簡體   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