Re: Compile query results into a table - Mailing list pgsql-admin

From David G. Johnston
Subject Re: Compile query results into a table
Date
Msg-id CAKFQuwb-dpROZB=w4Fuq0TC0w05_uVex9f28EMjTsdpaZumiQg@mail.gmail.com
Whole thread Raw
In response to Compile query results into a table  (Santosh Udupi <email@hitha.net>)
List pgsql-admin
On Thu, Jan 16, 2020 at 4:22 PM Santosh Udupi <email@hitha.net> wrote:


Sample calls to the function:

 // select * from dbo. test  ('search_in_authors')

// select * from dbo. test ('search_in_authors, search_in_editors')

// select * from dbo. test ('search_in_authors, search_in_editors,search_in_publishers ')

-----------------------------------------------------

 Are there any options in PostgreSQL to achieve this other than using a temp table ?

Since the names of the tables are dynamic you would need to use pl/pgsql and its EXECUTE capability and build up a useful SQL command on-the-fly.  To avoid using temporary tables you would need to put all the separate queries into the same main query.  This can be done with "UNION" and/(or?) Common Table Expressions (CTE - the WITH clause).

David J.

pgsql-admin by date:

Previous
From: Santosh Udupi
Date:
Subject: Compile query results into a table
Next
From: Ken Benson
Date:
Subject: delete then insert