The suggested query to list ENUM types is great. But, it merely lists of the schema
and the typname
. How do I list out the actual ENUM values? For
If you have the table and column name, (but not the type name) use this:
SELECT pg_enum.enumlabel
FROM pg_type
JOIN pg_enum ON pg_enum.enumtypid = pg_type.oid
JOIN information_schema.columns ON information_schema.columns.udt_name =
pg_type.typname
WHERE pg_type.typtype = 'e' AND
table_name = $1 AND column_name = $2 ORDER BY pg_enum.enumsortorder
If you use enum_range
on a column (in contrast to the other answers which used it on a type) it will return data for each row that exists, which is not what you want. So use the above query instead.
@dpb:
If you want to create a permanent easy access method for this, you could always create a view
CREATE OR REPLACE VIEW oublic.enumz AS
SELECT n.nspname AS enum_schema,
t.typname AS enum_name,
e.enumlabel AS enum_value
FROM pg_type t
JOIN pg_enum e ON t.oid = e.enumtypid
JOIN pg_namespace n ON n.oid = t.typnamespace;
You could then create a trigger for the insert command.
The above will store this in the database for future reference purposes.
This: SELECT unnest(enum_range(NULL::myenum))
returns enum types as rows.