JSqlParser
JSqlParser copied to clipboard
Cannot parse statement: Encountered unexpected token: "DEFERRABLE" "DEFERRABLE"
My code:
@Test
public void testJSQLParserValidation()
{
String sql = "CREATE TABLE SOMESCHEMA.SOMERELATIONTABLE (REL1_PK INT NOT NULL, REL2_PK "
+ "INT NOT NULL, CONSTRAINT REL1_REL2_PKS UNIQUE (REL1_PK, REL2_PK) "
+ "DEFERRABLE);";
Validation validation = new Validation(List.of(DatabaseType.POSTGRESQL), sql);
List<ValidationError> errors = validation.validate();
Assert.assertTrue( errors.toString(), errors.isEmpty());
}
Result:
java.lang.AssertionError: [ValidationError [
statement=CREATE TABLE SOMESCHEMA.SOMERELATIONTABLE (REL1_PK INT NOT NULL, REL2_PK INT NOT NULL, CONSTRAINT REL1_REL2_PKS UNIQUE (REL1_PK, REL2_PK) DEFERRABLE);
capability=parsing
errors=[ParseException: Cannot parse statement: Encountered unexpected token: "DEFERRABLE" "DEFERRABLE"
at line 1, column 139.
Was expecting one of:
"("
")"
"+"
","
"-"
"::"
"="
"ASC"
"BY"
"CASCADE"
"CHECK"
"COLLATE"
"COMMENT"
"COMMIT"
"CONSTRAINT"
"DEFAULT"
"DELETE"
"DESC"
"EXCLUDE"
"FALSE"
"FOREIGN"
"IN"
"KEY"
"NOT"
"NULL"
"ON"
"PARTITION"
"PRIMARY"
"REFERENCES"
"ROWS"
"TABLESPACE"
"TEMP"
"TEMPORARY"
"TRUE"
"TYPE"
"UNIQUE"
"UNSIGNED"
"UPDATE"
"USING"
"WHERE"
"WITH"
<K_TIME_KEY_EXPR>
<S_CHAR_LITERAL>
<S_DOUBLE>
<S_IDENTIFIER>
<S_LONG>
<S_QUOTED_IDENTIFIER>
]
]]
at org.junit.Assert.fail(Assert.java:89)
at org.junit.Assert.assertTrue(Assert.java:42)
Same for Oracle. This statement is valid and can be executed successfully on both.
This DEFERRABLE syntax is not supported.
Without it your statement is parsed and you can test it online here
What RDBMS uses DEFERRABLE please?
Actually supported syntax is shown here: http://217.160.215.75:8080/jsqlformatter/_static/railroad_diagram.xhtml#CreateTable
CONSTRAINT STATE has not been implemented yet, but PRs would be most welcome:

Closed when no further question has been asked.