Select from the table being updated

Select from the table being updated

am 29.12.2010 17:04:36 von Yves Goergen

Hi,

why doesn't MySQL support selecting from the table being updated? The
following and any variations of it doesn't work:

UPDATE t1 (c1) VALUES (SELECT MAX(c1) FROM t1);

This restriction is documented here:

http://dev.mysql.com/doc/refman/5.5/en/update.html (at the very bottom)

Wouldn't it be extremely useful to do that? If I want to copy a row and
only do minor changes to a single column, I don't want to read the other
huge column out to the client, only put write it back to the database
again unchanged. Or in the above example, I could find the next value,
like here:

UPDATE t1 (c1, c2)
VALUES ((SELECT MAX(c1) + 1 FROM t1 WHERE c2 = 5), 5);

Is it planned at all to add that? Is it really so complicated to do it
that it hasn't been done all those years?

The MySQL bug tracker was unable to filter the bugs down to less than a
few thousands, so I'm posting it here.

--
Yves Goergen "LonelyPixel"
Visit my web laboratory at http://beta.unclassified.de

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql-2@m.gmane.org