Re: enums

Поиск
Список
Период
Сортировка
От Michael Fuhr
Тема Re: enums
Дата
Msg-id 20051027234101.GA50434@winnie.fuhr.org
обсуждение исходный текст
Ответ на Re: enums  (Andrew Dunstan <andrew@dunslane.net>)
Ответы Re: enums  ("Jim C. Nasby" <jnasby@pervasive.com>)
Список 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 по дате отправления:

Предыдущее
От: Andrew Dunstan
Дата:
Сообщение: Re: enums
Следующее
От: Trent Shipley
Дата:
Сообщение: Re: enums