MySQL: some incompatibilities of queries with prior v5.0.12
I met some situations when old SQL queries don’t work under server v5.0.18. Of course I didn’t read before any migrations recommendations guides or something like this (I think, I’m not one like this). So I have just knew about this incompatibilities. I will fix here my experience with, that it help me to avoid errors like this in my sunny feature:
- Previously, the comma operator (
,) andJOINboth had the same precedence, so the join expressiont1, t2 JOIN t3was interpreted as((t1, t2) JOIN t3). NowJOINhas higher precedence, so the expression is interpreted as(t1, (t2 JOIN t3)). This change affects statements that use anONclause, because that clause can refer only to columns in the operands of the join, and the change in precedence changes interpretation of what those operands are.Example:
CREATE TABLE t1 (i1 INT, j1 INT);
CREATE TABLE t2 (i2 INT, j2 INT);
CREATE TABLE t3 (i3 INT, j3 INT);
INSERT INTO t1 VALUES(1,1);
INSERT INTO t2 VALUES(1,1);
INSERT INTO t3 VALUES(1,1);
SELECT * FROM t1, t2 JOIN t3 ON (t1.i1 = t3.i3);Previously, the
SELECTwas legal due to the implicit grouping oft1,t2as(t1,t2). Now theJOINtakes precedence, so the operands for theONclause aret2andt3. Becauset1.i1is not a column in either of the operands, the result is anUnknown column 't1.i1' in 'on clause'error. To allow the join to be processed, group the first two tables explicitly with parentheses so that the operands for theONclause are(t1,t2)andt3:SELECT * FROM (t1, t2) JOIN t3 ON (t1.i1 = t3.i3);Alternatively, avoid the use of the comma operator and use
JOINinstead:SELECT * FROM t1 JOIN t2 JOIN t3 ON (t1.i1 = t3.i3);This change also applies to statements that mix the comma operator with
INNER JOIN,CROSS JOIN,LEFT JOIN, andRIGHT JOIN, all of which now have higher precedence than the comma operator.
No Responses so far »
Comment RSS · TrackBack URI
Say your words