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

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

Open
lascarayf opened this issue Aug 10, 2018 · 1 comment
Labels

Comments

@lascarayf
Copy link

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
Copy link
Owner

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.

@olavloite olavloite changed the title jsqlparser ParseException JSqlParser ParseException - Boolean expression not allowed in select item Aug 12, 2018
@olavloite olavloite added the bug label Aug 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants