db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dag H. Wanvik (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (DERBY-6559) A immediate Fk constraint blows up iff its referenced PK is deferred and we delete a duplicate
Date Tue, 06 May 2014 20:08:19 GMT

    [ https://issues.apache.org/jira/browse/DERBY-6559?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13991059#comment-13991059
] 

Dag H. Wanvik edited comment on DERBY-6559 at 5/6/14 8:06 PM:
--------------------------------------------------------------

Thanks, Knut. Yes, I was wondering about whether there was some implicit commit there, but
I didn't get to looking it up. Good to get that clarified.
I also tried Postgresql on this with this result:
{code}
> create table t(i int, j int, constraint c primary key(i) deferrable);
> create table child(i int, constraint fk foreign key(i) references t(i) on delete set
null);
ERROR:  cannot use a deferrable unique constraint for referenced table "t"
{code}
So, they avoid the issue by being restrictive.

Documented in http://www.postgresql.org/docs/9.3/static/sql-createtable.html:
{quote}
The referenced columns must be the columns of a non-deferrable unique or primary key constraint
in the referenced table.
{quote}


was (Author: dagw):
Thanks, Knut. Yes, I was wondering about whether there was some implicit commit there, bu
tI didn't get to looking it up. Good to get that clarified.
I also tried Postgresql on this with this result:
{code}
> create table t(i int, j int, constraint c primary key(i) deferrable);
> create table child(i int, constraint fk foreign key(i) references t(i) on delete set
null);
ERROR:  cannot use a deferrable unique constraint for referenced table "t"
{code}
So, they avoid the issue by being restrictive.

Documented in http://www.postgresql.org/docs/9.3/static/sql-createtable.html:
{quote}
The referenced columns must be the columns of a non-deferrable unique or primary key constraint
in the referenced table.
{quote}

> A immediate Fk constraint blows up iff its referenced PK is deferred and we delete a
duplicate
> ----------------------------------------------------------------------------------------------
>
>                 Key: DERBY-6559
>                 URL: https://issues.apache.org/jira/browse/DERBY-6559
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL
>            Reporter: Dag H. Wanvik
>            Assignee: Dag H. Wanvik
>
> Cf the following test case:
> {code:title=testFKPlusUnique|borderStyle=solid}
>     /**
>      * The referenced constraint (in the referenced table) is also a deferred
>      * (unique/ok) constraint.
>      * 
>      * @throws SQLException 
>      */
>     public void testFKPlusUnique() throws SQLException {
>         Statement s = createStatement(
>                 ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
>         
>         try {
>             s.executeUpdate(
>                 "create table ref_t(i int, " +
>                 "    constraint ct primary key(i) deferrable initially deferred)");
>             s.executeUpdate(
>                 "create table t(i int unique not null, " +
>                 "    constraint c foreign key (i) references ref_t(i) " +
>                 "    deferrable initially immediate)");
>             
>             s.executeUpdate("insert into ref_t values 1,1");
>             s.executeUpdate("insert into t values 1");
>             
>             // Now, the child (referencing table) is referencing one of the the
>             // rows whose value is 1, so the reference is potentially suspect.
>             
>             // What happens when we delete the one copy before commit?
>             ResultSet rs = s.executeQuery("select * from ref_t");
>             rs.next();
>             
>             // Will this delete blow up? Hopefully not, here is another row
>             // that would satisfy the constraint.
>             rs.deleteRow();
>             
>             // Now there should be only one left, so the referenced table is
>             // OK.
>             commit();
>             :
> {code}
> Now, the constraint C throws when we do the "rs.deleteRow" above. But since there is
(still) a row satisfying the FK, albeit a duplicate, I believe it should not.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Mime
View raw message