Search code examples
sqlconcatenationgreenplum

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'

Solution

  • 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;