Re: [sqlite] Enforcing uniqueness from multiple indexes

2017-08-24 Thread Nico Williams
On Sun, Aug 20, 2017 at 05:17:16PM +, Wout Mertens wrote: > Oh wow, I didn't know about ON CONFLICT, thanks! > > Unfortunately the behavior on UPDATE (actually INSERT OR REPLACE in my > case) is not the desired behavior, it removes the row with the same k but > different id. PostgreSQL has so

Re: [sqlite] Enforcing uniqueness from multiple indexes

2017-08-20 Thread Wout Mertens
lite> select * from demo; > --EQP-- 0,0,0,SCAN TABLE demo > id|k|otherstuff > 1|30|Four-Mississippi > > sqlite> > > -Original Message- > From: sqlite-users [mailto:sqlite-users-boun...@mailinglists.sqlite.org] > On Behalf Of R Smith > Sent: Friday, August

Re: [sqlite] Enforcing uniqueness from multiple indexes

2017-08-18 Thread David Raymond
8 PM To: sqlite-users@mailinglists.sqlite.org Subject: Re: [sqlite] Enforcing uniqueness from multiple indexes On 2017/08/18 6:08 PM, R Smith wrote: > > Isn't this what conflict clauses on constraints are for? > Apologies, I usually add the test-case scripts in case anyone else wish to test it or sim

Re: [sqlite] Enforcing uniqueness from multiple indexes

2017-08-18 Thread R Smith
On 2017/08/18 6:08 PM, R Smith wrote: Isn't this what conflict clauses on constraints are for? Apologies, I usually add the test-case scripts in case anyone else wish to test it or similar, the case in question herewith added below: -- SQLite version 3.17.0 [ Release: 2017-02-13 ] on

Re: [sqlite] Enforcing uniqueness from multiple indexes

2017-08-18 Thread R Smith
On 2017/08/18 1:47 PM, Richard Hipp wrote: On 8/18/17, Wout Mertens wrote: So, bottom line, is there a way to insert or replace a row so that first the id constraint is observed (replacing a previous row with the same id), and then the k constraint is verified (failing to replace if k is alrea

Re: [sqlite] Enforcing uniqueness from multiple indexes

2017-08-18 Thread Nico Williams
An INSERT OR UPDATE sure would be nice. What i often do in cases like this is: UPDATE .. WHERE; INSERT .. SELECT .. WHERE NOT EXISTS (SELECT ..);. That's two statements -- if that's a problem, then you should use D. R. Hipp's trigger-based solution. ___

[sqlite] Enforcing uniqueness from multiple indexes

2017-08-18 Thread wout.mertens
The UNIQUE will either do nothing, or will erase existing lines if a trigger is forgotten. So not having the UNIQUE seems safer. ___ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sql

Re: [sqlite] Enforcing uniqueness from multiple indexes

2017-08-18 Thread Richard Hipp
On 8/18/17, Gerry Snyder wrote: > Should it be : > > CREATE UNIQUE INDEX ... I don't think it matters in this case. The trigger is also enforcing uniqueness. -- D. Richard Hipp d...@sqlite.org ___ sqlite-users mailing list sqlite-users@mailinglists.sq

Re: [sqlite] Enforcing uniqueness from multiple indexes

2017-08-18 Thread Gerry Snyder
Should it be : CREATE UNIQUE INDEX ... Gerry Snyder On Aug 18, 2017 4:47 AM, "Richard Hipp" wrote: > On 8/18/17, Wout Mertens wrote: > > > > So, bottom line, is there a way to insert or replace a row so that first > > the id constraint is observed (replacing a previous row with the same > id

Re: [sqlite] Enforcing uniqueness from multiple indexes

2017-08-18 Thread Wout Mertens
Splendid! Many thanks! On Fri, Aug 18, 2017 at 1:47 PM Richard Hipp wrote: > On 8/18/17, Wout Mertens wrote: > > > > So, bottom line, is there a way to insert or replace a row so that first > > the id constraint is observed (replacing a previous row with the same > id), > > and then the k const

Re: [sqlite] Enforcing uniqueness from multiple indexes

2017-08-18 Thread Richard Hipp
On 8/18/17, Wout Mertens wrote: > > So, bottom line, is there a way to insert or replace a row so that first > the id constraint is observed (replacing a previous row with the same id), > and then the k constraint is verified (failing to replace if k is already > present in the table)? CREATE TA

[sqlite] Enforcing uniqueness from multiple indexes

2017-08-18 Thread Wout Mertens
Hi, I have the following problem: I have data where two independent values need to be unique. I'm using one (id) as the primary key, and the other (let's call it k) should just cause insertion or updating to fail if it already exists in another row with a different id in the table. Furthermore, I