From: Haller Christoph <ch@rodos.fzk.de>
To: mk267673@but.auc.dk
Cc: pgsql-sql@postgresql.org
Subject: Re: Check for table existence
Date: Thu, 29 Nov 2001 15:58:33 MET
Message-ID: <200111291458.PAA05990@rodos> (raw)
In-Reply-To: <3C055B7E.BB52F0F1@but.auc.dk>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: ch@rodos.fzk.de, mk267673@but.auc.dk
Subject: Re: Check for table existence
In-Reply-To: <200111291458.PAA05990@rodos>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox