From: | dcrespo <dcrespo(at)gmail(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Solved: Getting the field names for a given table |
Date: | 2007-08-08 23:06:24 |
Message-ID: | 1186614384.209826.97100@d30g2000prg.googlegroups.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
For those who need to know the fields that a certain table has in a
postgresql database, here is the SQL statement:
SELECT DISTINCT attname, relname FROM pg_attribute pa, pg_class pc,
pg_tables pt WHERE pa.attrelid=pc.oid AND pc.relname=pt.tablename AND
pt.schemaname='public' AND attstattarget=-1 AND relname IN (SELECT
tablename FROM pg_tables WHERE schemaname='public') ORDER BY relname;
Notice that you can replace ***relname IN (SELECT tablename FROM
pg_tables WHERE schemaname='public')*** with
***relname='your_desired_tablename'*** and will do the work only for
an specific table. For the newbies: you can specify the schemaname if
needed.
Daniel
From | Date | Subject | |
---|---|---|---|
Next Message | Martijn van Oosterhout | 2007-08-09 00:14:24 | Re: Reordering columns, will this ever be simple? |
Previous Message | Martijn van Oosterhout | 2007-08-08 22:38:00 | Re: backend process terminates |