ParseException: Cannot parse statement: Encountered unexpected token: "exists" "EXISTS"
See original GitHub issueMy code:
@Test
public void testJSQParser()
{
String sql = "alter table if exists public.table2 rename to table3;";
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=alter table if exists public.table2 rename to table3;
capability=parsing
errors=[ParseException: Cannot parse statement: Encountered unexpected token: "exists" "EXISTS"
at line 1, column 16.
Was expecting one of:
"ADD"
"ALGORITHM"
"ALTER"
"CHANGE"
"COMMENT"
"DROP"
"MODIFY"
"RENAME"
]
]]
This statement is a valid PostgreSQL syntax.
Issue Analytics
- State:
- Created 2 years ago
- Comments:24 (23 by maintainers)
Top Results From Across the Web
ParseException: Cannot parse statement: Encountered unexpected ...
My code: @Test public void testJSQParser() { String sql = "alter table if exists public.table2 rename to table3;"; Validation validation = new ...
Read more >net.sf.jsqlparser.parser.ParseException - java - Stack Overflow
This seemed to be a dependency issue for me. This is the query I ran with the older version of the jsqlparser library:...
Read more >QMF V12.2 - Messages - IBM
Cannot parse data (base64 encoding rules violation); DAL01017 ... Parse exception occurred. ... Unexpected token: {0} is expected but {1} was found.
Read more >Troubleshoot 'Uncaught SyntaxError: Unexpected token u in ...
The 'Uncaught SyntaxError: Unexpected token u in JSON at position 0' error is caused when the client has been asked to execute JSON.parse() ......
Read more >How to fix Unexpected Token in JSON error (for ... - YouTube
Not a programmer? Read this! ** - If you get this error in an app you didn't make, and/or you're not a web...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The idea of JSQLParser is to manage all possible SQL syntax of various RDBMS in one Grammar definition.
It is not uncommon, I myself would also have taken a slightly different approach, e. g. defining a) a set of RDBMS which shall be supported and then b) find a way to flag each production for compatibility with a specific RDBMS. But that is only my gut feeling, the chosen approach is great for a lot of other objectives.
Why not volunteer and just add the Validator Rules for Oracle and Postgresql? Or set a bounty for other developers? The frame work is there already, all it needs is some fine-tuning now.
It is always good to know about options, but I myself came quite late for the party and stayed simply because I did not find anything even remotely as good as JSQLParser. Although I found a few short comings it was not too difficult to dive into the code and fill in what I was interested in myself.
Why not give it a try starting with the
RENAME oldName TO newname
statement and amend the Validator so it will accept Oracle and reject Postgresql.It’s about the definition of Feature’s and FeatureSetValidation (Version, DatabaseType). Only new features need an implementation within the Validator-classes. A new RDBMS to be validated only needs the definition of a new FeatureSet.
Personally I like the ANSI_SQL type the most, because it helps to write portable SQL, although this is not supported by all databases either.