From: | "Marin Dimitrov" <marin(dot)dimitrov(at)sirma(dot)bg> |
---|---|
To: | "Vincent Stoessel" <vincent(at)xaymaca(dot)com>, <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: if exists? |
Date: | 2002-05-13 15:25:54 |
Message-ID: | 003b01c1fa92$794838b0$9ba1d53e@sirma.bg |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
----- Original Message -----
From: "Vincent Stoessel"
> Is there an sql query that I can use on postgres that will tell
> me if a table exists?
select relname
from pg_class
where relowner = (select usesysid
from pg_user
where usename='USERNAME')
and relkind='r';
...will give u the list of all tables owned by user USERNAME
so something like:
select count(*)
from pg_class
where relname = 'TABLENAME'
and relkind='r'
and relowner = (select usesysid
from pg_user
where usename='USERNAME');
...will return 0 if the table does not exist
hth,
Marin
----
"...what you brought from your past, is of no use in your present. When
you must choose a new path, do not bring old experiences with you.
Those who strike out afresh, but who attempt to retain a little of the
old life, end up torn apart by their own memories. "
From | Date | Subject | |
---|---|---|---|
Next Message | Lee Kindness | 2002-05-13 15:26:14 | if exists? |
Previous Message | Oliver Elphick | 2002-05-13 15:24:36 | Re: Use of OIDS as primary keys |