From: | Andrew Dunstan <andrew(at)dunslane(dot)net> |
---|---|
To: | "Jim C(dot) Nasby" <jnasby(at)pervasive(dot)com> |
Cc: | ted(at)php(dot)net, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: enums |
Date: | 2005-10-27 23:02:45 |
Message-ID: | 43615C95.3090508@dunslane.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
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.
Otherwise, you could just as easily use a domain with a check constraint.
In fact, mysql's behaviour is laughably, even ludicrously, inconsistent:
mysql> select color from t order by color;
+-------+
| color |
+-------+
| red |
| blue |
| green |
+-------+
3 rows in set (0.06 sec)
mysql> select * from t where color < 'green';
+-------+
| color |
+-------+
| blue |
+-------+
So for "order by" it honors the enumeration order, but for < it uses the
lexical ordering. Lovely, eh?
cheers
andrew
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2005-10-27 23:02:54 | Re: ERROR: invalid memory alloc request size <a_big_number_here> |
Previous Message | Gregory Maxwell | 2005-10-27 22:46:24 | Re: enums |