Ryan Davis wrote:
> but honestly if you're doing this against a sequel db, you're it  
> wrong. You should use the power of the DB instead of doing tons of  
> roundtrips in ruby.

Right - what you want is:

SELECT id+1 FROM table AS t WHERE NOT EXISTS(SELECT * FROM table AS n WHERE t.id+1 = n.id) LIMIT 1

that is, find (just the first) successor of the first id that doesn't have a successor.

Otherwise just "SELECT max(id)+1 from table" if you don't need to fill vacated spots.

-- 
Clifford Heath, Data Constellation, http://dataconstellation.com
Agile Information Management and Design