简体   繁体   中英

Need the output in specific format in psql

Suppose:-

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

and

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

I am running this query :-

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

Actually I want the output to be as follows :-

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

use quote_literal

This function adds the single quote in front and back of given string/number. Read here .

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'

\\' will be used for adding quote

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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