Re: enums
От | Andrew Dunstan |
---|---|
Тема | Re: enums |
Дата | |
Msg-id | 43615C95.3090508@dunslane.net обсуждение исходный текст |
Ответ на | Re: enums ("Jim C. Nasby" <jnasby@pervasive.com>) |
Ответы |
Re: enums
Re: enums |
Список | 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
В списке pgsql-hackers по дате отправления: