What's wrong with the following (pseudo-code)? begin immediate x = result of (select max(j) from mytab;); ++x; for (n=0; n<num; n++) // num may be greater than or equal to zero { insert into mytab (j) values (x); } commit
Just don't forget to create index on j. Pavel On Thu, Oct 27, 2011 at 3:12 PM, Tim Streater <t...@clothears.org.uk> wrote: > Is there a way to get a unique id from a database without actually creating a > new row? If I have: > > create table mytab (i integer primary key, j); > > then I could do (pseudo-code): > > insert into mytab (i) values (null); > x = result of (select last_insert_rowid() from mytab;); > > for (n=0; n<num; n++) // num may be greater than or equal to zero > { > insert into mytab (j) values (x); > } > > delete from mytab where i=x; > > > This would give me my desired result of having a set of rows with the same > j-value (other columns differ, of course). The insert in the for-loop is > actually done elsewhere so it doing as above simplifies the logic. As num may > be zero I may not in fact need the unique value. What I'd like would be a way > of asking table mytab for a unique value that may or may not get used, but > without the need to thereby create a row that I later have to delete. > > -- > Cheers -- Tim > > _______________________________________________ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > > _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users