Last active
February 23, 2017 03:57
-
-
Save kamino410/e59c1441b6d70d2535a00280195474a7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT | |
| nsp.nspname AS schema, | |
| cls.relname AS table_name, | |
| own.rolname AS owner, | |
| dsc.description | |
| FROM | |
| pg_catalog.pg_class cls | |
| LEFT JOIN pg_catalog.pg_namespace nsp ON cls.relnamespace = nsp.oid | |
| LEFT JOIN pg_catalog.pg_authid own ON cls.relowner = own.oid | |
| LEFT JOIN pg_catalog.pg_description dsc ON cls.oid = dsc.objoid | |
| WHERE | |
| cls.relkind = 'r' AND nsp.nspname = 'public' | |
| AND (dsc IS NULL OR dsc.objsubid = 0) | |
| ORDER BY nsp.nspname, cls.relname; | |
| SELECT | |
| relname AS table_name | |
| FROM | |
| pg_catalog.pg_class cls | |
| LEFT JOIN pg_catalog.pg_namespace nsp ON cls.relnamespace = nsp.oid | |
| WHERE | |
| cls.relkind = 'r' AND | |
| nsp.nspname = 'public' | |
| ORDER BY nsp.nspname, cls.relname; | |
| SELECT | |
| att.attnum AS "no.", | |
| att.attname AS "column name", | |
| pg_catalog.format_type(att.atttypid, att.atttypmod) AS "type", | |
| (SELECT pg_catalog.pg_get_expr(d.adbin, d.adrelid) | |
| FROM pg_catalog.pg_attrdef d | |
| WHERE d.adrelid = att.attrelid AND d.adnum = att.attnum AND att.atthasdef) AS "default", | |
| att.attnotnull AS "not null", | |
| dsc.description | |
| FROM pg_catalog.pg_attribute att | |
| LEFT JOIN pg_catalog.pg_class cls ON att.attrelid = cls.oid | |
| LEFT JOIN pg_catalog.pg_type typ ON att.atttypid = typ.oid | |
| LEFT JOIN pg_catalog.pg_description dsc ON cls.oid = dsc.objoid AND att.attnum = dsc.objsubid | |
| WHERE | |
| cls.relname = :TABLENAME | |
| AND att.attnum >= 0 | |
| ORDER BY att.attnum; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment