Key violation

This forum is to report technical problems with Rel.
Post Reply
dportas
Posts: 3
Joined: Thu Aug 24, 2017 8:21 pm

Key violation

Post by dportas »

V: 3.007, OS: Windows 10

When I declare multiple keys it appears that only the first of the keys is enforced.

VAR foo REAL RELATION {a INTEGER, b INTEGER} KEY {a} KEY {b};

INSERT foo RELATION {TUPLE {a 1, b 1}};
INSERT foo RELATION {TUPLE {a 2, b 1}};

result:

a b
1 1
2 1
steved
Posts: 49
Joined: Sun Sep 01, 2013 10:53 pm

Re: Key violation

Post by steved »

Use D_INSERT:
D_INSERT foo RELATION {TUPLE {a 1, b 1}};
D_INSERT foo RELATION {TUPLE {a 2, b 1}};

ERROR: RS0232: Inserting tuple would violate uniqueness constraint of KEY {b}

stephen
dportas
Posts: 3
Joined: Thu Aug 24, 2017 8:21 pm

Re: Key violation

Post by dportas »

Thanks, D_INSERT does work as an alternative workaround. I'm more interested in reporting the bug than in finding workarounds. I wonder what other operations might also be affected if constraints aren't being enforced correctly.
Dave
Site Admin
Posts: 372
Joined: Sun Nov 27, 2005 7:19 pm

Re: Key violation

Post by Dave »

dportas wrote: Fri Aug 25, 2017 6:09 am Thanks, D_INSERT does work as an alternative workaround. I'm more interested in reporting the bug than in finding workarounds. I wonder what other operations might also be affected if constraints aren't being enforced correctly.
I've added this to my to-do list.

Note that KEY constraints are handled differently from other explicit constraints -- i.e., those declared with CONSTRAINT -- so a bug in KEY constraints does not imply a bug in CONSTRAINTs in general. Of course, there might be bugs in CONSTRAINTs in general; I can only state with certainty that they're not related to KEY constraints!

Notably (and perhaps annoyingly), INSERT correctly reports that it is not inserting a tuple, but does so anyway. E.g.:

var myvar5 real relation {x int, y int} key {x} key {y};

Ok.

insert myvar5 rel {tup {x 1, y 1}};

NOTICE: Inserted 1 tuple.

Ok.

insert myvar5 rel {tup {x 2, y 1}};

NOTICE: Inserted 0 tuples.

Ok.

myvar5
RELATION {x INTEGER, y INTEGER} {
TUPLE {x 1, y 1},
TUPLE {x 2, y 1}
}
Dave
Site Admin
Posts: 372
Joined: Sun Nov 27, 2005 7:19 pm

Re: Key violation

Post by Dave »

I've corrected this for the forthcoming v3.008 update.
Dave
Site Admin
Posts: 372
Joined: Sun Nov 27, 2005 7:19 pm

Re: Key violation

Post by Dave »

The version 3.008 update that fixes this bug is now available for download from http://reldb.org
dportas
Posts: 3
Joined: Thu Aug 24, 2017 8:21 pm

Re: Key violation

Post by dportas »

That was fast work! It has fixed the problem for me. Thanks.
Post Reply