Re: [sqlite] Is this safe use of SELECT in an INSERT?

2017-03-08 Thread Graham Holden
o: sqlite-users@mailinglists.sqlite.org Subject: Re: [sqlite] Is this safe use of SELECT in an INSERT? Graham Holden wrote: > insert or ignore into Servers values (    'MyServer',    12345,    ( select > count (*) from Servers ) ) > > is the "count (*)" guaranteed t

Re: [sqlite] Is this safe use of SELECT in an INSERT?

2017-03-08 Thread Clemens Ladisch
Graham Holden wrote: > insert or ignore into Servers values ('MyServer',12345,( select > count (*) from Servers ) ) > > is the "count (*)" guaranteed to be the count before the insert? Yes. But if any row was ever deleted, that value might alread by used. You could make serverIdx au

[sqlite] Is this safe use of SELECT in an INSERT?

2017-03-07 Thread Graham Holden
I want to keep a semi-persistent list of server/port pairs with an associated "index" that can be used to refer to entries elsewhere. Given: create table Servers (    serverName    text,    serverPort       integer,    serverIdx         integer unique,    primary key ( serverName, serverPort ) )