PostgreSQL Find missing ids in a sequence


/ Published in: SQL
Save to your folder(s)

http://postgresql.nabble.com/Simple-way-to-get-missing-number-tp5662154p5662212.html


Copy this code and paste it in your HTML
  1. SELECT generate_series(
  2. (SELECT MIN(id) FROM locations),
  3. (SELECT MAX(id) FROM locations)
  4. ) AS genid
  5. EXCEPT SELECT id FROM locations
  6. ORDER BY genid ASC;

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.