Skip to content

Commit

Permalink
fix(grammar): Support CONSTRAINTS keyword in inline and out-of-line c…
Browse files Browse the repository at this point in the history
…onstraints as an alternative to CONSTRAINT

Although it seems that this syntax has never been documented in the last 20 years in Oracle docs and causes parsing errors in Oracle SQL Developer, testing shows that it is still accepted by the Oracle 23.5 compiler.

Ref:
https://docs.oracle.com/cd/A87860_01/doc/server.817/a85397/state14a.htm (Oracle 8i docs)
https://docs.oracle.com/en/database/oracle/oracle-database/23/sqlrf/constraint.html (Oracle 23ai docs)
Based on debezium/debezium#5612
  • Loading branch information
felipebz committed Oct 11, 2024
1 parent 2a75820 commit 57117d0
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ enum class DdlGrammar : GrammarRuleKey {
)

b.rule(INLINE_CONSTRAINT).define(
b.optional(CONSTRAINT, IDENTIFIER_NAME),
b.optional(b.firstOf(CONSTRAINT, CONSTRAINTS), IDENTIFIER_NAME),
b.firstOf(
b.sequence(
b.firstOf(
Expand Down Expand Up @@ -160,7 +160,7 @@ enum class DdlGrammar : GrammarRuleKey {
b.zeroOrMore(INLINE_CONSTRAINT))

b.rule(OUT_OF_LINE_CONSTRAINT).define(
b.optional(CONSTRAINT, IDENTIFIER_NAME),
b.optional(b.firstOf(CONSTRAINT, CONSTRAINTS), IDENTIFIER_NAME),
b.firstOf(
b.sequence(
b.firstOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ enum class PlSqlKeyword(override val value: String, val isReserved: Boolean = fa
CONNECT_BY_ROOT("connect_by_root"),
CONSTANT("constant"),
CONSTRAINT("constraint"),
CONSTRAINTS("constraints"),
CONSTRUCTOR("constructor"),
CONTAINER("container"),
CONTENT("content"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class InlineConstraintTest : RuleTest() {
@Test
fun matchesConstraintWithName() {
assertThat(p).matches("constraint pk primary key")
assertThat(p).matches("constraints pk primary key")
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class OutOfLineConstraintTest : RuleTest() {
@Test
fun matchesConstraintWithName() {
assertThat(p).matches("constraint pk primary key (foo)")
assertThat(p).matches("constraints pk primary key (foo)")
}

@Test
Expand Down

0 comments on commit 57117d0

Please sign in to comment.