This project is archived and is in readonly mode.
Arel update method silently drops OFFSET clause
-
Hugo Peixoto
- Tag set to arel
In postgresql, that query gets converted to the something like the following:
UPDATE things SET broken = 1 WHERE id IN (SELECT id FROM things ORDER BY freshness ASC LIMIT 10)The OFFSET clause is ignored independently of the RDBMS. I made a patch that fixes this by converting the query to the following:
UPDATE things SET broken = 1 WHERE id IN (SELECT id FROM things ORDER BY freshness ASC LIMIT 10 OFFSET 20)Unfortunately, this is invalid in MySQL, as it doesn't support LIMIT/OFFSET in subqueries. One possible work-around (http://forums.mysql.com/read.php?86,14788,239000#msg-239000) is to create the following query:
UPDATE things SET broken = 1 WHERE id IN (SELECT id FROM (SELECT id FROM things ORDER BY freshness ASC LIMIT 10 OFFSET 20) alias)The patch I'm uploading does both. The first commit adds the ability to specify an OFFSET clause in an UPDATE statement, while the second commit adds this workaround so that it works in MySQL too.
Comments on this are welcome.
-
Hugo Peixoto
The previous patch had a problem. The WHERE conditions should not be in the parent UPDATE statement, but in the subselect one. This is related to Bug #6058").
The patch I'm attaching now removes the WHERE conditions from the UPDATE statement. As there is a bug regarding the where clauses propagation, the patch in the aforementioned ticket should also be applied.
