Re: pl sql to check if table of table_name exists

From: Chris Travers <chris(at)travelamericas(dot)com>
To: Shaun Clements <ShaunC(at)relyant(dot)co(dot)za>, pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: pl sql to check if table of table_name exists
Date: 2005-03-10 09:38:20
Message-ID: 4230158C.5040907@travelamericas.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Alban Hertroys 2005-03-10 09:50:59 Re: Disabling triggers in a transaction
Previous Message Net Virtual Mailing Lists 2005-03-10 09:31:21 Problem with inherited table, can you help?...