View of Union Multiple Tables - Only If table EXISTS

From: Avi Weinberg <AviW(at)gilat(dot)com>
To: "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: View of Union Multiple Tables - Only If table EXISTS
Date: 2021-07-25 14:01:38
Message-ID: DB9PR07MB718071BE91911B930C1DFC08CBE79@DB9PR07MB7180.eurprd07.prod.outlook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

I would like to create a view which is UNION of multiple tables with the same name from different schemas.

Select col1, col2 from schemaA.table
UNION
Select col1, col2 from schemaB.table

However, it is possible that in some of the schemas the table was not created yet.

I know I can check in which schemas the table exists and then create the view, but at any given time the table can be added to other schemas. In that case, I will always need to check if the view is up-to-date before accessing it and this makes the view useless.

Is it possible to write the view syntax once and it will do some type of SELECT IF EXISTS.

Thanks
Avi

IMPORTANT - This email and any attachments is intended for the above named addressee(s), and may contain information which is confidential or privileged. If you are not the intended recipient, please inform the sender immediately and delete this email: you should not copy or use this e-mail for any purpose nor disclose its contents to any person.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2021-07-25 14:06:27 Re: View of Union Multiple Tables - Only If table EXISTS
Previous Message Lucas 2021-07-25 08:33:59 Re: PostgreSQL 9.2 high replication lag