Re: enums

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: "Jim C(dot) Nasby" <jnasby(at)pervasive(dot)com>, ted(at)php(dot)net, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: enums
Date: 2005-10-27 23:41:01
Message-ID: 20051027234101.GA50434@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

  • Re: enums at 2005-10-27 23:02:45 from Andrew Dunstan

Responses

  • Re: enums at 2005-10-28 01:24:57 from Jim C. Nasby

Browse pgsql-hackers by date

  From Date Subject
Next Message Mark Kirkwood 2005-10-28 00:21:50 TODO Item - Add system view to show free space map contents
Previous Message Andrew Dunstan 2005-10-27 23:22:19 Re: enums