rockstardev
rockstardev

Reputation: 13527

Get values for ENUMs in Postgres?

I created an enum like this:

CREATE TYPE status as ENUM ('INVALID', 'VALID', 'EXPIRED');

How can I query the database to get the possible values for this enum? I tried something like this:

SELECT * FROM status;

Doesn't work. Any ideas as to how to do this?

Upvotes: 0

Views: 297

Answers (2)

Gunar Gessner
Gunar Gessner

Reputation: 2631

If psql, then \dT+:

\dT+ status

Upvotes: 0

user330315
user330315

Reputation:

Something like this:

select e.enumlabel
from pg_type t 
   join pg_enum e on t.oid = e.enumtypid  
   join pg_catalog.pg_namespace n ON n.oid = t.typnamespace
where t.typname = 'status'
  and n.nspname = 'public';

Upvotes: 2

Related Questions