Re: if exists? - Mailing list pgsql-general

From Marin Dimitrov
Subject Re: if exists?
Date
Msg-id 003b01c1fa92$794838b0$9ba1d53e@sirma.bg
Whole thread Raw
In response to if exists?  (Vincent Stoessel <vincent@xaymaca.com>)
List 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. "




pgsql-general by date:

Previous
From: Lee Kindness
Date:
Subject: if exists?
Next
From: Oliver Elphick
Date:
Subject: Re: if exists?