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
I always forget how to do this. As per the other answer and the comment, here it is a comma-separated list. I like copy-paste snippets. Thanks for the help:
select n.nspname as enum_schema,
t.typname as enum_name,
string_agg(e.enumlabel, ', ') as enum_value
from pg_type t
join pg_enum e on t.oid = e.enumtypid
join pg_catalog.pg_namespace n ON n.oid = t.typnamespace
group by enum_schema, enum_name;
select enum_range(enum_first(null::province),null::province);
This lists all enum-typed columns and their potential values:
SELECT
table_schema || '.' || table_name || '.' || column_name as field_name,
pg_enum.enumlabel as value
FROM pg_type
JOIN pg_enum ON pg_enum.enumtypid = pg_type.oid
JOIN pg_namespace on pg_type.typnamespace = pg_namespace.oid
JOIN information_schema.columns ON (information_schema.columns.udt_name = pg_type.typname AND information_schema.columns.udt_schema = pg_namespace.nspname)
WHERE pg_type.typtype = 'e'
ORDER BY field_name, pg_enum.enumsortorder;
You can list the data type via
\dT+ channels
https://www.postgresql.org/docs/current/static/app-psql.html#APP-PSQL-META-COMMANDS
Add order
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_catalog.pg_namespace n ON n.oid = t.typnamespace
ORDER BY
enum_name,
e.enumsortorder;
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_catalog.pg_namespace n ON n.oid = t.typnamespace