Issue Details (XML | Word | Printable)

Key: DERBY-158
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Jeremy Boynes
Reporter: Bernt M. Johnsen
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Derby

PRIMARY KEY does not imply NOT NULL

Created: 04/Mar/05 06:46 AM   Updated: 04/May/05 04:02 AM
Return to search
Component/s: SQL
Affects Version/s: None
Fix Version/s: 10.1.1.0

Time Tracking:
Not Specified

File Attachments:
  Size
Text File Licensed for inclusion in ASF works derby-158-1.patch 2005-03-05 01:37 PM Jeremy Boynes 8 kB
Text File Licensed for inclusion in ASF works derby-158-2.patch 2005-03-06 06:14 AM Jeremy Boynes 16 kB

Resolution Date: 09/Mar/05 06:25 AM


 Description  « Hide
PRIMARY KEY does not imply NOT NULL. Derby issues error message:

ij> create table tab (i integer primary key);
ERROR 42831: 'I' cannot be a column of a primary key or unique key because it can contain null values.

This is neither compliant with SQL-92 nor with SQL-99 (Feature E141-08, I think).


 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Jeremy Boynes made changes - 05/Mar/05 01:29 PM
Field Original Value New Value
Assignee Jeremy Boynes [ jboynes ]
Jeremy Boynes added a comment - 05/Mar/05 01:37 PM
Patch to TableElementList that implicitly adds NOT NULL to columns included in a PRIMARY KEY constraint contained in a CREATE TABLE statement. However, it does not allow UNIQUE to be added in CREATE TABLE if any of the columns are NULL; similarly UNIQUE or PRIMARY KEY constraints cannot be added with ALTER TABLE if any of the columns are nullable.

I am posting this first for review as a couple of tests still need to be updated.

Jeremy Boynes made changes - 05/Mar/05 01:37 PM
Attachment derby-158-1.patch [ 19114 ]
Jeremy Boynes added a comment - 06/Mar/05 06:14 AM
Patch to TableElementList plus test changes.
If I don't hear anything I'll commit this in a couple of days.

Jeremy Boynes made changes - 06/Mar/05 06:14 AM
Attachment derby-158-2.patch [ 19120 ]
Repository Revision Date User Message
ASF #156570 Tue Mar 08 21:22:59 UTC 2005 jboynes Fix for DERBY-158 PRIMARY KEY does not imply NOT NULL
Columns specified in a PRIMARY KEY constraint in CREATE TABLE
are implicitly set to NOT NULL per the SQL spec.

If a PRIMARY KEY constraint is added using ALTER TABLE then all
columns must also be NOT NULL. Similarly, columns
specified in a UNIQUE constraint must still be explictly NOT NULL.
Files Changed
MODIFY /incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/primarykey.out
MODIFY /incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/nulls.sql
MODIFY /incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/db2Compatibility.sql
MODIFY /incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/primarykey.sql
MODIFY /incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/nulls.out
MODIFY /incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableElementList.java
MODIFY /incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/db2Compatibility.out

Jeremy Boynes added a comment - 09/Mar/05 06:25 AM
URL: http://svn.apache.org/viewcvs?view=rev&rev=156570
Log:
Fix for DERBY-158 PRIMARY KEY does not imply NOT NULL
Columns specified in a PRIMARY KEY constraint in CREATE TABLE
are implicitly set to NOT NULL per the SQL spec.

If a PRIMARY KEY constraint is added using ALTER TABLE then all
columns must also be NOT NULL. Similarly, columns
specified in a UNIQUE constraint must still be explictly NOT NULL.

Modified:
    incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableElementList.java
    incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/db2Compatibility.out
    incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/nulls.out
    incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/primarykey.out
    incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/db2Compatibility.sql
    incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/nulls.sql
    incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/primarykey.sql

Jeremy Boynes made changes - 09/Mar/05 06:25 AM
Status Open [ 1 ] Resolved [ 5 ]
Fix Version/s 10.1.0.0 [ 10993 ]
Resolution Fixed [ 1 ]
Bernt M. Johnsen made changes - 04/May/05 04:02 AM
Status Resolved [ 5 ] Closed [ 6 ]