db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rick Hillegas (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (DERBY-2212) Add "Unique where not null" to create index
Date Thu, 02 Nov 2017 00:59:00 GMT

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

Rick Hillegas commented on DERBY-2212:

Can you describe your use case which is not satisfied by the work on DERBY-3330 (allowing
nullable columns in unique constraints)? Unique constraints now behave as seen in the following

connect 'jdbc:derby:memory:db;create=true';

create table t(a int, b int, unique(a, b));

insert into t(a) values (1);
insert into t values (1, 1);
insert into t(b) values (1);

insert into t(a) values (1);

-- fails: The statement was aborted because it would have caused a duplicate key value
insert into t values (1, 1);

-- succeeds
insert into t(b) values (1);

-- returns
-- 1    1
-- 1    NULL
-- 1    NULL
-- NULL 1
-- NULL 1
select * from t order by a, b;


> Add "Unique where not null" to create index
> -------------------------------------------
>                 Key: DERBY-2212
>                 URL: https://issues.apache.org/jira/browse/DERBY-2212
>             Project: Derby
>          Issue Type: Improvement
>          Components: SQL
>    Affects Versions:
>            Reporter: Oleksandr Alesinskyy
>            Priority: Major
>              Labels: derby_triage10_10
>         Attachments: FunctionalSpec.html, FunctionalSpecV3.html, FunctionalSpecV3_comment.html,
FunctionlaSpecv2.html, derby-2212preview.diff, derby-2212preview2.diff
> Derby prohibits creation of unique constraints on nullable colums (as well if only some
columns in the constraint list are nullable) and treat nulls in unique indexes as normal values
(i.e. only one row with null values in indexed columns may be inserted into the table). This
bahavior is very restrictive, does not completely comply with SQL standards (both letter and
intent) as well as with business needs and intending meaning of NULL values (2 null values
are not considered as equal, this comparision shall return NULL, and for selection criteria
boolean null is treated as FALSE).
> This behavior, as far as I can see, is modelled after DB2 (and differs from behavior
of most other major databases, like SyBase, Oracle, etc.).
> But even DB2 provide some means to alleviate these restrictions, namely "UNIQUE WHERE
NOT NULL" clause for CREATE INDEX statement.
> It will be very good if such "UNIQUE WHERE NOT NULL" clause will be introduced in Derby.
> Regards,
> Oleksandr Alesinskyy

This message was sent by Atlassian JIRA

View raw message