Search code examples
sqldatabasepostgresqlsql-deletegenerate-series

Delete range of rows using generate_series()?


To update every row in a table, I use this query (and it's working):

enter image description here

I wonder if I can use a similar notation for DELETE?

Something like:

DELETE from test2
from generate_series(1, 1000) as idx
WHERE id = idx;

Won't work as the second FROM is invalid, of course. Any idea how to fix that?

What is the best practice for this kind of operation?


Solution

  • Use USING:

    DELETE from test2 
           using generate_series(1, 1000) idx
           WHERE id = idx