Re: Retrieving database schema
От | Lamar Owen |
---|---|
Тема | Re: Retrieving database schema |
Дата | |
Msg-id | 200303222257.52775.lamar.owen@wgcr.org обсуждение исходный текст |
Ответ на | Retrieving database schema (Gary M <postgres-general@mwwm.net>) |
Ответы |
Re: Retrieving database schema
Re: Retrieving database schema |
Список | pgsql-general |
On Saturday 22 March 2003 22:33, Gary M wrote: > From embedded SQL - how do I retrieve > 1) a list of the tables in the datbase? > 2) a list of the columns in each table? > > > Perhaps #1 is this: > > SELECT tablename FROM pg_tables WHERE NOT schemaname = 'pg_catalog'; I use the following, although it uses pre-7.0 semantics and may or may not work with 7.3 SELECT relname FROM pg_class WHERE relkind = 'r' and relname !~ '^Inv' and relname !~ '^pg_' ORDER BY relname I don't remember the reason for the ^Inv regex. > I'm at a loss for #2 I use the following query, which also gives the type of the column. $table is the table in question. SELECT a.attname, t.typname FROM pg_class c, pg_attribute a, pg_type t WHERE c.relname = lower($table) and a.attnum > 0 and a.attrelid = c.oid and a.atttypid = t.oid ORDER BY attname Again, using pre-7.x semantics, as the code that uses these queries might be used on PostgreSQL as old as 6.4.2. -- Lamar Owen WGCR Internet Radio 1 Peter 4:11
В списке pgsql-general по дате отправления: