Received: from druid.net (root@druid.net [216.126.72.98]) by hub.org (8.9.3/8.9.3) with ESMTP id HAA96921 for ; Tue, 17 Aug 1999 07:19:02 -0400 (EDT) (envelope-from darcy@druid.net) Received: from localhost (2150 bytes) by druid.net via sendmail with P:stdio/R:bind_hosts/T:inet_zone_bind_smtp (sender: ) (ident using unix) id for ; Tue, 17 Aug 1999 07:19:00 -0400 (EDT) (Smail-3.2.0.104 1998-Nov-20 #4 built 1999-Apr-13) Message-Id: Subject: Re: [INTERFACES] A few more JDBC meta-data questions... In-Reply-To: <37B8A5B4.A85541A0@phalanx.net> from Mark Dzmura at "Aug 16, 1999 11:58:44 pm" To: mdz@phalanx.phalanx.net (Mark Dzmura) Date: Tue, 17 Aug 1999 07:19:00 -0400 (EDT) From: "D'Arcy" "J.M." Cain Cc: pgsql-interfaces@postgreSQL.org X-Mailer: ELM [version 2.4ME+ PL50 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Thus spake Mark Dzmura > 1. Is it possible to programatically enumerate or discover the databases in a running database?? > > 2. Is it possible to programmaticaly enumerate or discover the tables in a database?? -- get list of databases SELECT datname FROM pg_database; -- get list of tables including views but not system tables SELECT relname FROM pg_class WHERE relkind = 'r' AND relname !~ '^Inv' AND relname !~ '^pg_'; And for completeness; -- get list of attributes and types for a specific table SELECT pg_attribute.attname, pg_type.typname FROM pg_class, pg_attribute, pg_type WHERE pg_class.relname = 'tablename' AND pg_attribute.attnum > 0 AND pg_attribute.attrelid = pg_class.oid AND pg_attribute.atttypid = pg_type.oid; -- get list of tables and primary keys (assumes no complex keys) -- only includes tables with primary keys so no views SELECT pg_class.relname, pg_attribute.attname FROM pg_class, pg_attribute, pg_index WHERE pg_class.oid = pg_attribute.attrelid AND pg_class.oid = pg_index.indrelid AND pg_index.indkey[0] = pg_attribute.attnum AND pg_index.indisprimary = 't'; -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 424 2871 (DoD#0082) (eNTP) | what's for dinner.