Received: from fzkmail2.fzk.de (fzkmail2.fzk.de [141.52.27.52]) by postgresql.org (8.11.3/8.11.4) with SMTP id fATF0xm72575 for ; Thu, 29 Nov 2001 10:00:59 -0500 (EST) (envelope-from ch@rodos.fzk.de) Received: FROM resy5.fzk.de BY fzkmail2.fzk.de ; Thu Nov 29 16:00:58 2001 +0100 Received: by rodos.fzk.de with ESMTP (8.8.6 (PHNE_17135)/8.7.1) id QAA12421; Thu, 29 Nov 2001 16:04:34 +0100 (MET) From: Haller Christoph Message-Id: <200111291458.PAA05990@rodos> Subject: Re: Check for table existence To: mk267673@but.auc.dk (Michael Knudsen) Date: Thu, 29 Nov 2001 15:58:33 MET Cc: pgsql-sql@postgresql.org In-Reply-To: <3C055B7E.BB52F0F1@but.auc.dk>; from "Michael Knudsen" at Nov 29, 101 2:21 pm X-Mailer: Elm [revision: 212.4] X-Archive-Number: 200111/411 X-Sequence-Number: 5793 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