Skip to content

Instantly share code, notes, and snippets.

@sawirricardo
Created January 20, 2024 08:31
Show Gist options
  • Save sawirricardo/752bbcc15203d82edf33a6527007c57a to your computer and use it in GitHub Desktop.
Save sawirricardo/752bbcc15203d82edf33a6527007c57a to your computer and use it in GitHub Desktop.
Select types for postgresql
select
t.typname as name,
n.nspname as schema,
t.typtype as type,
t.typcategory as category,
(
(
t.typinput = 'array_in'::regproc
and t.typoutput = 'array_out'::regproc
)
or t.typtype = 'm'
) as implicit
from
pg_type t
join pg_namespace n on n.oid = t.typnamespace
left join pg_class c on c.oid = t.typrelid
left join pg_type el on el.oid = t.typelem
left join pg_class ce on ce.oid = el.typrelid
where
(
(
t.typrelid = 0
and (
ce.relkind = 'c'
or ce.relkind is null
)
)
or c.relkind = 'c'
)
and not exists (
select
1
from
pg_depend d
where
d.objid in (t.oid, t.typelem)
and d.deptype = 'e'
)
and n.nspname not in ('pg_catalog', 'information_schema');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment