Skip to content

nested typecast via :: not handled #614

@ted-johnson

Description

@ted-johnson

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions