Created
June 21, 2023 01:22
-
-
Save apinanyogaratnam/72027c1a56d894e6c4dfdcaeaf6c5524 to your computer and use it in GitHub Desktop.
Query all enums in postgres
This file contains 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 ( | |
col.table_schema, | |
col.table_name, | |
col.ordinal_position as column_id, | |
col.column_name, | |
col.udt_name, | |
string_agg(enu.enumlabel, ', ' ORDER BY enu.enumsortorder) AS enum_values | |
) | |
FROM information_schema.columns col | |
JOIN information_schema.tables tab ON tab.table_schema = col.table_schema | |
AND tab.table_name = col.table_name | |
AND tab.table_type = 'BASE TABLE' | |
JOIN pg_type typ ON col.udt_name = typ.typname | |
JOIN pg_enum enu ON typ.oid = enu.enumtypid | |
WHERE col.table_schema not in ('information_schema', 'pg_catalog') | |
AND typ.typtype = 'e' | |
GROUP BY col.table_schema, | |
col.table_name, | |
col.ordinal_position, | |
col.column_name, | |
col.udt_name | |
ORDER BY col.table_schema, | |
col.table_name, | |
col.ordinal_position; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment