Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGROUP BY Month(dateField) not working #482
Comments
|
Have we missed something...? Is there something we are meant to be calling to make this work? Or is it not implimented yet? We cannot find any reference to this issue or implimentation anywhere. |
|
I have introduced a test using your SQL (SelectTest.testGroupByProblemIssue482). It parses without any parser modification. |
|
We are using the latest (1.1). Here is our code - I am not sure if we are missing something. EDIT: Trying to format code to make it easier to read - sorry, didn't mean to close issue. `package com.woogloo.api.data.userdb; import com.woogloo.common.DataAPI; /**
|
|
Tested the following code snipped using JSqlParser 0.9.5 with success. No problems in parsing your SQL:
I assume the exception is thrown within your constructor, right? Then the rest of your code is not relevant. Maybe there are some invisible control characters within your sql, that are stripped by copy paste. You see, I have no clue, why you get this exception. |
|
Worked for me for 1.2-SNAPSHOT: import org.junit.Test;
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
import net.sf.jsqlparser.statement.Statements;
import net.sf.jsqlparser.statement.select.Select;
public class Issue482Test {
@Test
public void test() throws Exception {
String sql = "SELECT SUM(orderTotalValue) as value, MONTH(invoiceDate) as month, YEAR(invoiceDate) as year FROM invoice.Invoices WHERE projectID = 1 GROUP BY MONTH(invoiceDate), YEAR(invoiceDate) ORDER BY YEAR(invoiceDate) DESC, MONTH(invoiceDate) DESC";
Select select = (Select) CCJSqlParserUtil.parse(sql);
System.out.println(select.toString());
Statements stmts = CCJSqlParserUtil.parseStatements(sql);
System.out.println(stmts.toString());
}
}
I can attach the result of |
|
So at least two developers are able to parse your query successfully. Should we close it? Do our simple examples work for you? |
|
closing due to no response |
A valid H2 Database query is not working with JSQLParser.
Here is the original query:
SELECT SUM(orderTotalValue) as value, MONTH(invoiceDate) as month, YEAR(invoiceDate) as year FROM invoice.Invoices WHERE projectID = 1 GROUP BY MONTH(invoiceDate), YEAR(invoiceDate) ORDER BY YEAR(invoiceDate) DESC, MONTH(invoiceDate) DESC
Having pulled it to bits until we discovered which part was not working, we discovered the GROUP BY MONTH(invoiceDate), YEAR(invoiceDate) was the issue. Even with just GROUP BY MONTH(invoiceDate) it still didn't work.
The error thrown was:
sf. jsqlparser. parser. ParseException: Encountered " "(" "( "" at line 1, column 142. Was expecting one of: "LIMIT" . . . "ORDER" . . . "OFFSET" . . . "HAVING" . . . ";" . . . "," . . . ". " . . . ". " . . . "," . . . "HAVING" . . . "ORDER" . . . "LIMIT" . . . "OFFSET" . . . "LIMIT" . . . at net. sf. jsqlparser. parser. CCJSqlParser. generateParseException(CCJSqlParser. java:5359) at net. sf. jsqlparser. parser. CCJSqlParser. jj_consume_token(CCJSqlParser. java:5235) at net. sf. jsqlparser. parser. CCJSqlParser. Statement(CCJSqlParser. java:146) at net. sf. jsqlparser. parser. CCJSqlParserManager. parse(CCJSqlParserManager. java:38)
Have updated to the latest version - still not working.