Search Postgresql Archives

Solved: Getting the field names for a given table

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
       subscribe-nomail command to majordomo@xxxxxxxxxxxxxx so that your
       message can get through to the mailing list cleanly

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux