forked from sqlpad/sqlpad
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema-postgres.sql
More file actions
21 lines (21 loc) · 797 Bytes
/
Copy pathschema-postgres.sql
File metadata and controls
21 lines (21 loc) · 797 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
select
case cls.relkind when 'r' then 'Tables' when 'v' then 'Views' when 'm' then 'Views' end as table_type,
ns.nspname as table_schema,
cls.relname as table_name,
attr.attname as column_name,
trim(leading '_' from tp.typname) as data_type,
case attr.attnotnull when true then 'NO' when false then 'YES' end as is_nullable
from
pg_catalog.pg_attribute as attr
join pg_catalog.pg_class as cls on cls.oid = attr.attrelid
join pg_catalog.pg_namespace as ns on ns.oid = cls.relnamespace
join pg_catalog.pg_type as tp on tp.typelem = attr.atttypid
where
cls.relkind in ('r', 'v', 'm')
and ns.nspname not in ('pg_catalog', 'pg_toast', 'information_schema')
and not attr.attisdropped
and attr.attnum > 0
order by
ns.nspname,
cls.relname,
attr.attnum