Created
February 25, 2015 21:43
-
-
Save Voronenko/599d49d57632ae3adebe to your computer and use it in GitHub Desktop.
Postgre list user defined types
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 n.nspname AS schema, | |
pg_catalog.format_type ( t.oid, NULL ) AS name, | |
t.typname AS internal_name, | |
CASE | |
WHEN t.typrelid != 0 | |
THEN CAST ( 'tuple' AS pg_catalog.text ) | |
WHEN t.typlen < 0 | |
THEN CAST ( 'var' AS pg_catalog.text ) | |
ELSE CAST ( t.typlen AS pg_catalog.text ) | |
END AS size, | |
pg_catalog.array_to_string ( | |
ARRAY( SELECT e.enumlabel | |
FROM pg_catalog.pg_enum e | |
WHERE e.enumtypid = t.oid | |
ORDER BY e.oid ), E'\n' | |
) AS elements, | |
pg_catalog.obj_description ( t.oid, 'pg_type' ) AS description | |
FROM pg_catalog.pg_type t | |
LEFT JOIN pg_catalog.pg_namespace n | |
ON n.oid = t.typnamespace | |
WHERE ( t.typrelid = 0 | |
OR ( SELECT c.relkind = 'c' | |
FROM pg_catalog.pg_class c | |
WHERE c.oid = t.typrelid | |
) | |
) | |
AND NOT EXISTS | |
( SELECT 1 | |
FROM pg_catalog.pg_type el | |
WHERE el.oid = t.typelem | |
AND el.typarray = t.oid | |
) | |
AND n.nspname <> 'pg_catalog' | |
AND n.nspname <> 'information_schema' | |
AND pg_catalog.pg_type_is_visible ( t.oid ) | |
ORDER BY 1, 2; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment