Bug #39 Aggregate function inside susbselect works in strange manner.
Description:
UPDATE t SET i=i+1 WHERE i=(SELECT MAX(i));
is accepted silently (does nothing, but no erroir) and refuses to execute second time. Then after SELECT this behaviour repeats.
I am not sure what is semantics of (SELECT MAX(i)) here as there is No FROM and if there is:
mysql> UPDATE t SET i=i+1 WHERE i=(SELECT MAX(i) FROM t);
ERROR 1093: You can't specify target table 't' for update in FROM clause
Which is nice error message.
Question is: Why does first UPDATE works in this strange manner?
How to repeat:
mysql> CREATE TABLE `t` (
-> `i` int(11) NOT NULL default '0',
-> PRIMARY KEY (`i`)
-> ) TYPE=MyISAM CHARSET=latin1
-> ;
Query OK, 0 rows affected (0.02 sec)
mysql> INSERT INTO t VALUES (1);
Query OK, 1 row affected (0.02 sec)
mysql> UPDATE t SET i=i+1 WHERE i=(SELECT MAX(i));
Query OK, 0 rows affected (0.02 sec)
Rows matched: 0 Changed: 0 Warnings: 0
# Note zeroes here!
mysql> UPDATE t SET i=i+1 WHERE i=(SELECT MAX(i));
ERROR 1111: Invalid use of group function
# Sounds better than silence above.
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.047 sec. using MySQL 8.4.7-u6-cloud
Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the
respective copyright holders.
It is not reviewed in advance
by Oracle and does not necessarily represent the opinion of
Oracle or any other party.
Description: UPDATE t SET i=i+1 WHERE i=(SELECT MAX(i)); is accepted silently (does nothing, but no erroir) and refuses to execute second time. Then after SELECT this behaviour repeats. I am not sure what is semantics of (SELECT MAX(i)) here as there is No FROM and if there is: mysql> UPDATE t SET i=i+1 WHERE i=(SELECT MAX(i) FROM t); ERROR 1093: You can't specify target table 't' for update in FROM clause Which is nice error message. Question is: Why does first UPDATE works in this strange manner? How to repeat: mysql> CREATE TABLE `t` ( -> `i` int(11) NOT NULL default '0', -> PRIMARY KEY (`i`) -> ) TYPE=MyISAM CHARSET=latin1 -> ; Query OK, 0 rows affected (0.02 sec) mysql> INSERT INTO t VALUES (1); Query OK, 1 row affected (0.02 sec) mysql> UPDATE t SET i=i+1 WHERE i=(SELECT MAX(i)); Query OK, 0 rows affected (0.02 sec) Rows matched: 0 Changed: 0 Warnings: 0 # Note zeroes here! mysql> UPDATE t SET i=i+1 WHERE i=(SELECT MAX(i)); ERROR 1111: Invalid use of group function # Sounds better than silence above.