Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

275
Views
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?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Use USING:

DELETE from test2 
       using generate_series(1, 1000) idx
       WHERE id = idx
over 4 years ago · Santiago Trujillo Report

0

What is the best practice for this kind of operation?

You can use generate_series() like Gordon demonstrates. This might even make sense for non-integer types or with an increment <> 1.
For simple cases, the simple query is superior, though:

DELETE FROM test2 
WHERE  id BETWEEN 1 AND 1000;
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!