Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nested typecast via :: not handled #614

Closed
ted-johnson opened this issue May 9, 2018 · 1 comment
Closed

nested typecast via :: not handled #614

ted-johnson opened this issue May 9, 2018 · 1 comment

Comments

@ted-johnson
Copy link
Contributor

The :: syntax is a shorthand for CAST
A valid Postgresql expression such as
('x'||substr(md5(hostname),1,16))::bit(64)::bigint as id_,
results in a parse error.

The problem is that in JSqlParserCC.jjt, the repetition block for :: specifies zero or 1 occurrences
(that is, enclosed in square braces [ ... ])

The fix is to specify zero or more occurrences.
at line 2505 or so in JSqlParserCC.jjt, change the code from

[ "::" type=ColDataType() {
castExpr = new CastExpression();
castExpr.setUseCastKeyword(false);
castExpr.setLeftExpression(retval);
castExpr.setType(type);
retval=castExpr;
} ]

to

( "::" type=ColDataType() {
castExpr = new CastExpression();
castExpr.setUseCastKeyword(false);
castExpr.setLeftExpression(retval);
castExpr.setType(type);
retval=castExpr;
} )*

I rebuilt JSqlParser using
mvn package
and the revised code passes all tests.

The revised code parsers the statement, and the default SQL generator returns the :: sequence.

@wumpz
Copy link
Member

wumpz commented May 9, 2018

Could you provide a pull request?

@wumpz wumpz closed this as completed in 32c4d8a May 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants