Posted By

djmornyc on 12/09/10


Tagged

sql table comments postgres schema


Versions (?)

Postgres get table schema with columns


 / Published in: SQL
 

Get table schema with columns via sql.

  1. SELECT
  2. ordinal_position,
  3. column_name,
  4. data_type,
  5. is_nullable,
  6. description.description AS comment
  7. FROM
  8. information_schema.COLUMNS COLUMNS
  9. LEFT JOIN pg_class class ON (COLUMNS.table_name = class.relname)
  10. LEFT JOIN pg_description description ON (class.oid = description.objoid)
  11. LEFT JOIN pg_attribute attrib ON (class.oid = attrib.attrelid AND COLUMNS.column_name = attrib.attname AND attrib.attnum = description.objsubid)
  12. WHERE
  13. table_name='{$tableName}'
  14. GROUP BY
  15. ordinal_position, column_name, data_type, is_nullable, description.description

Report this snippet  

You need to login to post a comment.