Received: from fzkmail2.fzk.de (fzkmail2.fzk.de [141.52.27.52]) by postgresql.org (Postfix) with SMTP id 7E8394750F5 for ; Fri, 12 Jul 2002 08:16:52 -0400 (EDT) Received: FROM resy5.fzk.de BY fzkmail2.fzk.de ; Fri Jul 12 14:16:54 2002 +0200 Received: œby rodos.fzk.de with ESMTP (8.8.6 (PHNE_17135)/8.7.1) id OAA06312; Fri, 12 Jul 2002 14:16:53 +0200 (METDST) From: Christoph Haller Message-Id: <200207121216.OAA09315@rodos> Subject: Re: list of tables ? To: SBrett@e-mis.com (Steve Brett) Date: Fri, 12 Jul 2002 14:16:52 METDST Cc: pgsql-sql@postgresql.org In-Reply-To: ; from "Steve Brett" at Jul 11, 102 4:02 pm X-Mailer: Elm [revision: 212.4] X-Archive-Number: 200207/183 X-Sequence-Number: 8562 > > can anyone point me in the right direction ? > > i need to list all the tables in a database. > Steve, Your request reminds me of a similar problem I had. Try the following: CREATE VIEW sesql_usertables AS SELECT UPPER(u.usename) AS tbl_owner, UPPER(c.relname) AS tbl_name, UPPER(a.attname) AS col_name, a.atttypid AS col_type, INT4LARGER(a.attlen, a.atttypmod - 4) AS col_length, CASE WHEN a.attnotnull=TRUE THEN 0 ELSE 1 END AS col_null, a.attnum AS col_seq, CASE WHEN EXISTS(SELECT adsrc FROM pg_attrdef d WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum) THEN 1 ELSE 0 END AS COL_DEFAULT FROM pg_attribute a, pg_class c LEFT JOIN pg_user u ON (u.usesysid = c.relowner) WHERE c.oid = a.attrelid AND NOT (c.relname ~* 'pg_') AND c.relkind = 'r' AND a.attnum > 0 ; SELECT * FROM sesql_usertables ORDER BY tbl_owner, tbl_name, col_seq ; It should give at least some ideas how to retrieve information from all the tables in a database. Regards, Christoph