Re: Check for table existence - Mailing list pgsql-sql

From Haller Christoph
Subject Re: Check for table existence
Date
Msg-id 200111291458.PAA05990@rodos
Whole thread Raw
In response to Check for table existence  (Michael Knudsen <mk267673@but.auc.dk>)
List 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 


pgsql-sql by date:

Previous
From: Markus Bertheau
Date:
Subject: Re: Fixing faulty dates - select on day part of a date field
Next
From: Stephan Szabo
Date:
Subject: Re: PL/pgSQL loops?