Issue Details (XML | Word | Printable)

Key: DERBY-331
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Dag H. Wanvik
Reporter: Gin Ng
Votes: 0
Watchers: 0
Operations

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

create table fails when a constraint defintion follows a column default

Created: 01/Jun/05 04:02 AM   Updated: 10/Jun/06 09:01 PM
Return to search
Component/s: SQL
Affects Version/s: 10.0.2.1
Fix Version/s: 10.1.3.1, 10.2.1.6

Time Tracking:
Not Specified

File Attachments:
  Size
File Licensed for inclusion in ASF works 331b.diff 2005-06-21 01:08 AM Dag H. Wanvik 3 kB
File Licensed for inclusion in ASF works 331b.stat 2005-06-21 01:08 AM Dag H. Wanvik 0.2 kB
Environment: Windows XP

Resolution Date: 10/Jun/06 09:01 PM


 Description  « Hide
The following statement fails with syntax error.

ij> create table t (a int not null, b int default 0, unique (a));
ERROR 42X01: Syntax error: Encountered "0" at line 1, column 47.

And it will work if I remove either default 0 or unique(a).


 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Satheesh Bandaram added a comment - 08/Jun/05 07:58 AM
That doesn't seem to be the correct syntax. Derby supports column level constraints, in the format:

ij> create table t ( a int not null unique, b int default 0);
0 rows inserted/updated/deleted

Or table level constraints, like:

ij> create table t (a int not null, b int default 0, constraint tk unique (a));
0 rows inserted/updated/deleted

See documentation at:
http://incubator.apache.org/derby/docs/ref/rrefsqlj13590.html

Gin Ng added a comment - 08/Jun/05 11:25 PM
The constraint name is optional. See http://incubator.apache.org/derby/docs/ref/rrefsqlj16095.html.
And my example is in the same form of the second example in the document above except the default value.

-- the table-level primary key definition allows you to
-- include two columns in the primary key definition:
CREATE TABLE SAMP.SCHED
(
CLASS_CODE CHAR(7) NOT NULL,
DAY SMALLINT NOT NULL,
STARTING TIME,
ENDING TIME,
PRIMARY KEY (CLASS_CODE, DAY)
);

Dag H. Wanvik added a comment - 11/Jun/05 12:10 AM
This seems to be a look-ahead problem in the parser. I think I have a patch for it, just need to run all tests.

Dag H. Wanvik added a comment - 11/Jun/05 03:43 AM
This patch fixes a look-ahead problem in the parser: In the method DB2DefaultOption,
the look-ahead for miscBuiltins is too liberal: it mistakenly thinks it has found a
builtin in this case. I made the look-ahead more specific by adding a check against comma.
 I have extended the test lang/columnDefaults.sql with this case.
I have run derbyall with no errors.

Dag H. Wanvik added a comment - 21/Jun/05 01:08 AM
Updated this patch which additional comments, according to Mamta's suggestion.
Ran the test lang/columnDefaults.sql again to verify.


Daniel John Debrunner added a comment - 09/Jul/05 01:55 AM
Committed revision 209842 (331b.diff)
Sorry for missing this one, noticed it the other day when looking at the release notes, but didn't get back to it.

Mayuresh Nirhali added a comment - 08/Jun/06 07:26 PM
This bug is 10.1 branch porting candidate for 10.1.3 release.

I merged the changes (209842) into my fresh 10.1 branch child. The changes applied cleanly.
I rebuilt the workspace and ran the corresponding test, lang,columnDefaults.sql. The test passed.
derbyall also did not show any relevant failures.

I think the already attached patch can be directly merg/committed to 10.1 branch.

Knut Anders Hatlen added a comment - 10/Jun/06 05:38 PM
This issue is marked as fixed in 10.1.3.0, but it is not. Reopening to merge to the 10.1 branch.

Knut Anders Hatlen added a comment - 10/Jun/06 09:01 PM
Committed into 10.1 with revision 413299.