Re: if exists / where exisyts....

Поиск
Список
Период
Сортировка
От Ron Johnson
Тема Re: if exists / where exisyts....
Дата
Msg-id 1022254332.2286.11.camel@rebel
обсуждение исходный текст
Ответ на if exists / where exisyts....  (Denis Cartier Millon <Denis.CM@Wanadoo.fr>)
Список pgsql-interfaces
On Fri, 2002-05-24 at 09:12, Denis Cartier Millon wrote:
> i want to test if a table exists before to drop this......
> 
> the :
> if exists (select 1 from pg_tables where tablename = "thetable")
> drop table thetable
> ;
> 
> don't work....

I'd use the system catalogs:
test2=# select count(*) from pg_class where relname = 'foo';count 
-------    1
(1 row)

test2=# select count(*) from pg_class where relname = 'snaggle';count 
-------    0
(1 row)

You can use it for tables, views, indexes (and maybe other
things).

-- 
+---------------------------------------------------------+
| Ron Johnson, Jr.        Home: ron.l.johnson@cox.net     |
| Jefferson, LA  USA      http://ronandheather.dhs.org:81 |
|                                                         |
| "I have created a government of whirled peas..."        |
|   Maharishi Mahesh Yogi, 12-May-2002,                   |
!   CNN, Larry King Live                                  |
+---------------------------------------------------------+



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

Предыдущее
От: Denis Cartier Millon
Дата:
Сообщение: if exists / where exisyts....
Следующее
От: Bruce Momjian
Дата:
Сообщение: Re: [HACKERS] Schemas: status report, call for developers