Xaitec
Xaitec

Reputation: 129

How do i query values of an enum in postgresql

Hi i want to use an enum in postgresql as an alternative to making a table, because the values my never change, but i want to be able to retrieve these values for an application that might check just in case they do, is there any way the query it to get the values?

Upvotes: 5

Views: 4776

Answers (2)

Justin Ohms
Justin Ohms

Reputation: 3523

SELECT unnest(enum_range(NULL::your_enum))::text AS your_column

This will return a single column result set of the contents of the enum "your_enum" with a column named "your_column" of type text.

Upvotes: 10

Richard Huxton
Richard Huxton

Reputation: 54

See the manual: Functions and Operators / Enum Support Functions You probably want the enum_range(...) function. Alternatively, you could look in the system catalogues: pg_enum

Upvotes: 0

Related Questions