Re: enums - Mailing list pgsql-hackers

From Michael Fuhr
Subject Re: enums
Date
Msg-id 20051027234101.GA50434@winnie.fuhr.org
Whole thread Raw
In response to Re: enums  (Andrew Dunstan <andrew@dunslane.net>)
Responses Re: enums
List pgsql-hackers
On Thu, Oct 27, 2005 at 07:02:45PM -0400, Andrew Dunstan wrote:
> Jim C. Nasby wrote:
> >On another note, I noticed that the comparison operators seem to be
> >comparing the underlying numeric value used to store the enum, which is
> >wrong IMO. Consider:
> >
> >ENUM color '"red","blue","green"'
> >CREATE TABLE t (c color);
> >INSERT INTO t VALUES('blue');
> >INSERT INTO t VALUES('green');
> >INSERT INTO t VALUES('red');
> >SELECT c FROM t ORDER BY c;
> >red
> >blue
> >green
> >
> >That seems counter-intuitive. It's also exposing an implimentation
> >detail (that the enum is stored internally as a number).
> 
> No it is not. Not in the slightest. It is honoring the enumeration order 
> defined for the type. That is the ONLY correct behaviour, IMNSHO. 

I agree.  Honoring the enumeration order makes sense if you consider
the values as things that should be ordered based on some property
of their thingness instead of based on what their labels happen to
be in a particular language.  If I have an enumeration of colors I
might want values sorted by their position in the spectrum, so
whether the labels are (red, green, blue) or (gorri, berde, urdin)
I might want to maintain that particular order.

If you want values ordered lexically then you can enumerate them
that way.  Why force that behavior on people who want to order based
on some other criteria?

-- 
Michael Fuhr


pgsql-hackers by date:

Previous
From: Andrew Dunstan
Date:
Subject: Re: enums
Next
From: Trent Shipley
Date:
Subject: Re: enums