When querying the datatype using format_type(tttypid, atttypmod) from pg_attribute, I would like to return the ENUM values like atttypmod values.
attname | type
--------+-------------------------------
a | numeric(12,3)
b | timestamp(0) without time zone
enum | color('Red', 'Green', 'Blue')
Currently, the format_type() call only returns the enum name without values. I believe I need to CASE my select statement against the pg_type and pg_enum tables, but am having trouble with the proper syntax. My attempt is below. Thank you!
SELECT
attname,
CASE
WHEN format_type(atttypid, atttypmod)::text = ANY(select ARRAY(select t.typname::text from pg_type t join pg_enum e on t.oid = e.enumtypid group by t.typname))
THEN format_type(atttypid, atttypmod) || '(' || array_to_string(enum_range(NULL::format_type(atttypid, atttypmod)), ',') || ')'
ELSE format_type(atttypid, atttypmod)
END AS type
FROM pg_attribute
WHERE attrelid = 'myTable'::regclass
AND attnum > 0
AND NOT attisdropped
ORDER BY attnum;