[EMAIL PROTECTED] wrote: > I have a related question. Suppose I have a table containing rows each with > values and a counter. If the new row is unique in the table it should be > INSERTed and the counter set to 1; otherwise the counter for the matching > row should be incremented. It's a classic data reduction procedure. > > As most of the operations will be UPDATEs I want to do something like > UPDATE ... if failed INSERT... > but I can't see an efficient way to express that in SQL understood by > sqlite. > > Thanks,
Don't worry so much about efficiency until you're sure you have a problem. insert or ignore into tbl (primaryKey, counter, otherVal, ...) values (thisPK, 0, thisOtherVal, ...); update tbl set counter = counter + 1 where primaryKey = thisPK; Regards