Encountered unexpected token: "DATE_SUB" S_IDENTIFIER
See original GitHub issueActual Behavior
public static void main(String[] args) throws JSQLParserException {
String sql = "-- type 1 stands for sth1, 2 stands for sth2...\n" +
"SELECT count(1)\n" +
"FROM table_name\n" +
"WHERE 1 = 1\n" +
"AND uid = 1\n" +
"AND type IN (1, 2, 3)\n" +
"AND time >= TIMESTAMP(DATE_SUB(CURDATE(),INTERVAL 2 DAY),'00:00:00')\n" +
"AND time < TIMESTAMP(DATE_SUB(CURDATE(),INTERVAL (2 - 1) DAY),'00:00:00')";
Statement parse = new CCJSqlParserManager().parse(new StringReader(sql));
System.out.println(parse);
}
above code throws and exception:
Exception in thread "main" net.sf.jsqlparser.JSQLParserException
at net.sf.jsqlparser.parser.CCJSqlParserManager.parse(CCJSqlParserManager.java:40)
Caused by: net.sf.jsqlparser.parser.ParseException: Encountered unexpected token: "DATE_SUB" <S_IDENTIFIER>
at line 8, column 22.
Was expecting one of:
"+"
at net.sf.jsqlparser.parser.CCJSqlParser.generateParseException(CCJSqlParser.java:18597)
at net.sf.jsqlparser.parser.CCJSqlParser.jj_consume_token(CCJSqlParser.java:18447)
at net.sf.jsqlparser.parser.CCJSqlParser.RegularCondition(CCJSqlParser.java:6278)
at net.sf.jsqlparser.parser.CCJSqlParser.Condition(CCJSqlParser.java:5931)
at net.sf.jsqlparser.parser.CCJSqlParser.AndExpression(CCJSqlParser.java:5893)
at net.sf.jsqlparser.parser.CCJSqlParser.OrExpression(CCJSqlParser.java:5818)
at net.sf.jsqlparser.parser.CCJSqlParser.Expression(CCJSqlParser.java:5789)
at net.sf.jsqlparser.parser.CCJSqlParser.WhereClause(CCJSqlParser.java:5146)
at net.sf.jsqlparser.parser.CCJSqlParser.PlainSelect(CCJSqlParser.java:3082)
at net.sf.jsqlparser.parser.CCJSqlParser.SetOperationList(CCJSqlParser.java:3235)
at net.sf.jsqlparser.parser.CCJSqlParser.SelectBody(CCJSqlParser.java:2946)
at net.sf.jsqlparser.parser.CCJSqlParser.Select(CCJSqlParser.java:2939)
at net.sf.jsqlparser.parser.CCJSqlParser.SingleStatement(CCJSqlParser.java:130)
at net.sf.jsqlparser.parser.CCJSqlParser.Statement(CCJSqlParser.java:81)
at net.sf.jsqlparser.parser.CCJSqlParserManager.parse(CCJSqlParserManager.java:38)
... 1 more
Expected Behavior
hope that can support date_add / date_sub
method
Steps to Reproduce the Problem
- import jsqlparse-1.3
- run java code in IntelliJ IDEA
- exception happened
Specifications
- Version: jsqlparser-1.3
- Platform: OS X EI Capitan(10.11.6), jdk8, mysql
- Subsystem:
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Error in Google BigQuery <EOF> - sql - Stack Overflow
I need help on a query error: "Encountered " "WITH" "with "" at line 1, column 1. Was expecting: EOF". WITH is supported...
Read more >Solved: SQL Query Failed with Cloudera Hive JDBC driver bu...
In this query I am using ':custId' to fetch the customer id from property (coming from test data file in soap ui). Please...
Read more >MyBatisPlus解析WEEK关键字出现异常的踩坑记录 - CSDN博客
ParseException: Encountered unexpected token: "CURDATE" ... SELECT xxx FROM (SELECT yyy FROM a WHERE create_time >= date_sub(CURDATE(), ...
Read more >Unexpected Token on setting Datetime Variable
Please review the snippit below: dateTime dt = date.today()-90; public String query = 'SELECT Name, LastLoginDate, Id From User WHERE IsActive = ...
Read more >pyspark.sql module - Apache Spark
LongType column named id, containing elements in a range from start to end ... When a length of parsed CSV tokens is shorter...
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
i meet this with “date_add”…
Parses fine with JSQLParser 4.6 Snapshot:
c Closed.