If you have a table and column name (but not a 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 in a column (unlike the other answers that used it for the type), it will return data for every existing row, which you don't want. Therefore, use the above query.
Ariel May 01 '17 at 12:57 a.m. 2017-05-01 00:57
source share