Re: pl sql to check if table of table_name exists - Mailing list pgsql-general

From Chris Travers
Subject Re: pl sql to check if table of table_name exists
Date
Msg-id 4230158C.5040907@travelamericas.com
Whole thread Raw
In response to Re: pl sql to check if table of table_name exists  (Shaun Clements <ShaunC@relyant.co.za>)
List pgsql-general
Shaun Clements wrote:

> Hi
>
> Hate to ask, but it isnt obvious to me from the documentation.
> How do I perform a query in pgplsql, to check it a table exists of a
> particular name.
>
Check the manual.  There are two ways to d othis.  You could query the
data catalogs directly (something like count(*) from pg_class where
relname = $1), but this is not preferred because you have the
possibilities that the data catalogs will be changed in the future.

The better way to do this is to query the information schema.  I forget
the table name but it may be something like (select count(*) from
information_schema.tables where table_name = $1).  the structure of the
information schema is defined in the SQL standards and will be stable
between versions.

Best Wishes,
Chris Travers
Metatron Technology COnsulting

> Thanks in advance
>
> Kind Regards,
> Shaun Clements
>


pgsql-general by date:

Previous
From: "Net Virtual Mailing Lists"
Date:
Subject: Problem with inherited table, can you help?...
Next
From: Alban Hertroys
Date:
Subject: Re: Disabling triggers in a transaction