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
---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match