Re: Check if table exists

From: "Riccardo G(dot) Facchini" <abief_ag_-postgresql(at)yahoo(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Check if table exists
Date: 2004-12-17 12:48:35
Message-ID: 20041217124835.61824.qmail@web13908.mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


--- "ON.KG" <__> wrote:

> Hi ALL!
>
> I need to check before selection records from table - does this table
> exist
> How can i do that?
>
> Thanx in advance
>
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to
> majordomo(at)postgresql(dot)org
>

Option 1: tells you if the table exists in your database

select *
from pg_catalog.pg_tables as t
where t.schemaname = '<your schema name>' and
t.tablename = '<your table name';

Option 2: tells you if the table exists in your database and if is
visible in your search path (i.e. no need to select * from
schema.table, only select * from table)

select *
from pg_catalog.pg_class as c left outer join
pg_catalog.pg_namespace as n on
n.oid = c.relnamespace
where n.nspname = '<your schema name>' and
c.relname = '<your table name' and
pg_catalog.pg_table_is_visible(c.oid);

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Riccardo G. Facchini 2004-12-17 12:51:08 Re: Check if table exists
Previous Message Richard_D_Levine 2004-12-17 12:47:49 Re: pl/pgsql oddity