Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Does PostgreSQL have an enum data type?

Status
Not open for further replies.

aardvark92

Programmer
Oct 15, 2004
138
US
I'm moving to PostgreSQL after using MySQL for a few years. One of MySQL's features is an enum data type, which is used to select from a list.

For example, I might declare a field
Code:
rating ENUM("good","fair","poor")
to limit it to those three values.

I haven't found an exact equivalent in PostgreSQL. Is there one, or do I need to use the CONSTRAINT clause to limit a field's allowed values?
 
There is no datatype ENUM in PostgreSQL, but it is quite easy to handle this with a CHECK constraint --
Often it is a better design choice to use foreign key constraints with validation tables to accomplish this sort of constraint, because it allows your database model to evolve more flexibly.

-------------------------------------------

My PostgreSQL FAQ --
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top