From: | Haller Christoph <ch(at)rodos(dot)fzk(dot)de> |
---|---|
To: | mk267673(at)but(dot)auc(dot)dk (Michael Knudsen) |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Check for table existence |
Date: | 2001-11-29 15:58:33 |
Message-ID: | 200111291458.PAA05990@rodos |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Hi Michael,
>
>
> 1. How can I check if a given table exists?
> 2. How can I check if a given existing table has the right layout? (Correct
> column names and types)
>
Try this
create view my_tbldescription as
select
u.usename, t.typname AS tblname,
a.attname, a.atttypid, n.typname AS atttypname,
int4larger(a.attlen, a.atttypmod - 4) AS atttyplen,
a.attnotnull, a.attnum
from pg_user u, pg_type t, pg_attribute a, pg_type n
where u.usesysid = t.typowner
and t.typrelid = a.attrelid and t.typtype = 'c' and not (t.typname ~* 'pg_')
and n.typelem = a.atttypid
and substr(n.typname, 1, 1) = '_'
and a.attnum > 0 ;
select * from my_tbldescription order by 1,2,8 ;
It should tell you all you want to know.
Regards, Christoph
From | Date | Subject | |
---|---|---|---|
Next Message | Stephan Szabo | 2001-11-29 16:09:48 | Re: PL/pgSQL loops? |
Previous Message | dejauser2001@yahoo.co.uk | 2001-11-29 15:54:52 | Need help with a college SQL exam question... |