0

I've been trying to get all the possible values of a column whose type is an array of enum (ENUM[]) in Postgresql using a SQL request.

The usual method that uses the field data_type from the table information_schema.columns doesn't work as it only returns ARRAY.

Megacier
  • 394
  • 4
  • 9

2 Answers2

1

The following worked:

SELECT enumlabel
FROM pg_enum
         INNER JOIN pg_type ON enumtypid = typelem
         INNER JOIN information_schema.columns ON typname = udt_name
         INNER JOIN pg_namespace ON pg_namespace.oid = typnamespace
WHERE table_name = 'TABLE_NAME'
  AND column_name = 'COLUMN_NAME'
  AND nspname = 'public'
);
Megacier
  • 394
  • 4
  • 9
0

With psql, you can simply use \dT+:

\dT+ t_enum 
                                       List of data types
 Schema  │  Name  │ Internal name │ Size │ Elements │  Owner  │ Access privileges │ Description 
═════════╪════════╪═══════════════╪══════╪══════════╪═════════╪═══════════════════╪═════════════
 laurenz │ t_enum │ t_enum        │ 4    │ one     ↵│ laurenz │                   │ 
         │        │               │      │ two     ↵│         │                   │ 
         │        │               │      │ three    │         │                   │ 
(1 row)
Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263
  • It does answer the question but I was looking for a SQL request. I edited the question. Thanks for your answer! – Megacier Oct 07 '21 at 13:00