Re: DELETE with LIMIT (or my first hack) - Mailing list pgsql-hackers

From Valentine Gogichashvili
Subject Re: DELETE with LIMIT (or my first hack)
Date
Msg-id AANLkTikfYdhC8-N8hO5dNbgNK7SDPoZO4WYr6JapevDR@mail.gmail.com
Whole thread Raw
In response to Re: DELETE with LIMIT (or my first hack)  (Daniel Loureiro <loureirorg@gmail.com>)
Responses Re: DELETE with LIMIT (or my first hack)  (Marko Tiikkaja <marko.tiikkaja@cs.helsinki.fi>)
List pgsql-hackers
Hi, 

actually introducing LIMIT and OFFSET with ORDER BY to DELETE/UPDATE would make it much easier to push data from one (say "queue") table to another. And to fetch chunks of queue entries updating their status in one statement. Now I have to do SELECT...ORDER BY...LIMIT and then do some magic with arrays of IDs and updates/deletes or UPDATE ... WHERE id in (SELECT .. ORDER BY... LIMIT) RETURNING ... to make that work, but this is still possible to do with the WHERE clause, though I am not quite sure if that is most efficient in comparison to the direct approach. And speaking about pushing data from one table to another, what I really would like to be able to do would be also something like:

INSERT INTO ...
DELETE FROM ... WHERE... ORDER BY.. [LIMIT...]
RETURNING...;

this would be also quite efficient when re-arranging data in table partitions (though LIMIT/OFFSET there will be just nice to have possibility for reducing chunk sized of data being moved).

Additionally we need quite often to clean up some log tables depending not on the timestamps but on the number of rows in that tables, so leaving only last N newest records in a table... OFFSET would be really cool to have for that usecase as well...

With best regards,  

-- Valentine Gogichashvili

pgsql-hackers by date:

Previous
From: Itagaki Takahiro
Date:
Subject: Re: pg_execute_from_file review
Next
From: Magnus Hagander
Date:
Subject: Re: Improved JDBC driver part 2