Re: Check if table exists

Поиск
Список
Период
Сортировка
От Riccardo G. Facchini
Тема Re: Check if table exists
Дата
Msg-id 20041217125108.68126.qmail@web13907.mail.yahoo.com
обсуждение исходный текст
Ответ на Check if table exists  ("ON.KG" <skyer@on.kg>)
Список pgsql-general
Sorry: I forgot to add something to option 2

--- "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@postgresql.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
        c.relkind = 'r' and
        pg_catalog.pg_table_is_visible(c.oid);


В списке pgsql-general по дате отправления:

Предыдущее
От: "ON.KG"
Дата:
Сообщение: Re: Check if table exists
Следующее
От: Christopher Browne
Дата:
Сообщение: Re: Scheduler in Postgres