If I have a table that is empty and I want to compute an incrementing value in a 
non-unique column (I cannot use integer primary key since the column value won't be 
unique):

(select max(c) from t where n=20)+1

where c is unique only within (n==20), then this works as long as the table has at 
least one row where c is an integer value. However if the table is empty then max(c) 
is an empty string and the +1 causes a SQL error. Here's the example:

sqlite> create table t (c integer);
sqlite> insert into t (c) values ((select max(c) from t)+1);
sqlite> select * from t;

sqlite> insert into t (c) values (1);
sqlite> select * from t;

1
sqlite> insert into t (c) values ((select max(c) from t)+1);
sqlite> select * from t;

1
2
sqlite> 

Is there a workaround so I don't need to seed the table with a specific value for c in 
the first place?
Thanks!


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to