Created
May 3, 2020 10:15
-
-
Save rizalgowandy/981a78a6984ec97941ae9638ff0737ad to your computer and use it in GitHub Desktop.
PostgreSQL Get Table Schema
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 object_schema, | |
cls.relname as object_name, | |
rol.rolname as owner, | |
case cls.relkind | |
when 'r' then 'TABLE' | |
when 'm' then 'MATERIALIZED_VIEW' | |
when 'i' then 'INDEX' | |
when 'S' then 'SEQUENCE' | |
when 'v' then 'VIEW' | |
when 'c' then 'TYPE' | |
else cls.relkind::text | |
end as object_type | |
from pg_class cls | |
join pg_roles rol on rol.oid = cls.relowner | |
join pg_namespace nsp on nsp.oid = cls.relnamespace | |
where nsp.nspname not in ('information_schema', 'pg_catalog') | |
and nsp.nspname not like 'pg_toast%' | |
-- and rol.rolname = current_user --- remove this if you want to see all objects | |
order by nsp.nspname, cls.relname; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment