Postgres get table schema with columns


/ Published in: SQL
Save to your folder(s)

Get table schema with columns via sql.


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.