Lists: | pgsql-interfaces |
---|
From: | Denis Cartier Millon <Denis(dot)CM(at)Wanadoo(dot)fr> |
---|---|
To: | pgsql-interfaces(at)postgresql(dot)org |
Cc: | frederic(dot)mougin(at)agriculture(dot)gouv(dot)fr |
Subject: | if exists / where exisyts.... |
Date: | 2002-05-24 14:12:32 |
Message-ID: | 3CEE4A50.2090802@Wanadoo.fr |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-interfaces |
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 try :
wher e exists (....)
;
don't work.
but the expresssion :
select * from pg_tables where exists(select 1 from pg_tables where
tablename = "thetable")
;
work
From: | Ron Johnson <ron(dot)l(dot)johnson(at)cox(dot)net> |
---|---|
To: | pgsql-interfaces(at)postgresql(dot)org |
Subject: | Re: if exists / where exisyts.... |
Date: | 2002-05-24 15:32:08 |
Message-ID: | 1022254332.2286.11.camel@rebel |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | 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(dot)l(dot)johnson(at)cox(dot)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 |
+---------------------------------------------------------+