olavloite / spanner-jdbc

JDBC Driver for Google Cloud Spanner
MIT License
38 stars 10 forks source link

JSqlParser ParseException - Boolean expression not allowed in select item #97

Open lascarayf opened 6 years ago

lascarayf commented 6 years ago

Hi @olavloite. I have this error.

SELECT IF(2 > 1, 'A', 'B') FROM notifications;
Caused by: nl.topicus.jdbc.shaded.net.sf.jsqlparser.parser.ParseException: Encountered " "IF" "IF "" at line 1, column 8.
Was expecting one of:
    "ALL" ...
    "TOP" ...
    "NULL" ...
    "CASE" ...
    "DISTINCT" ...
    "INTERVAL" ...
    "UNIQUE" ...
    "GROUP_CONCAT" ...
    "SKIP" ...
    <K_TIME_KEY_EXPR> ...
    <S_CHAR_LITERAL> ...
    "*" ...
    "{d" ...
    "{t" ...
    "{ts" ...

    at nl.topicus.jdbc.shaded.net.sf.jsqlparser.parser.CCJSqlParser.generateParseException(CCJSqlParser.java:16869)
    at nl.topicus.jdbc.shaded.net.sf.jsqlparser.parser.CCJSqlParser.jj_consume_token(CCJSqlParser.java:16722)
    at nl.topicus.jdbc.shaded.net.sf.jsqlparser.parser.CCJSqlParser.PrimaryExpression(CCJSqlParser.java:6699)
    at nl.topicus.jdbc.shaded.net.sf.jsqlparser.parser.CCJSqlParser.BitwiseXor(CCJSqlParser.java:6257)
    at nl.topicus.jdbc.shaded.net.sf.jsqlparser.parser.CCJSqlParser.MultiplicativeExpression(CCJSqlParser.java:6214)
    at nl.topicus.jdbc.shaded.net.sf.jsqlparser.parser.CCJSqlParser.AdditiveExpression(CCJSqlParser.java:6176)
olavloite commented 6 years ago

Hi @lascarayf I have filed an issue (JSQLParser/JSqlParser#658) with the underlying project that I use for the SQL parsing, and I will see if I can submit a solution to it as well. In the meantime you could use the following work around:

SELECT IF(CASE WHEN 2 > 1 THEN TRUE ELSE FALSE END, 'A', 'B') FROM notifications;

The above statement should work and yield the same result.