JSqlParser icon indicating copy to clipboard operation
JSqlParser copied to clipboard

`DAY TO SECOND` is not supported

Open realizm opened this issue 6 years ago • 6 comments

Actual Behavior

Caused by: net.sf.jsqlparser.parser.ParseException: Encountered unexpected token: "DAY" <S_IDENTIFIER> at line 1, column 71.

Was expecting one of:

"&"
")"
"::"
"<<"
">>"
"^"
"|"

at net.sf.jsqlparser.parser.CCJSqlParser.generateParseException(CCJSqlParser.java:18047)

Expected Behavior

Steps to Reproduce the Problem

String sql = "select EXTRACT(DAY FROM (SYSDATE - to_date('20180101', 'YYYYMMDD' ) ) DAY TO SECOND) from dual;";

JSqlParser jSqlParser = new CCJSqlParserManager(); try { jSqlParser.parse(new StringReader(sql)); } catch (JSQLParserException e) { e.printStackTrace(); }

Specifications

  • Version:
  • Platform:
  • Subsystem:

realizm avatar Sep 04 '18 01:09 realizm

How to solve this? Facing the same problem

Mvpanswer7 avatar Oct 09 '18 06:10 Mvpanswer7

DAY FROM ... and DAY TO ... are not supported since it is not SQL Standard compliant. You can either provide or sponsor an implementation for the platform specific syntax.

manticore-projects avatar Apr 30 '23 12:04 manticore-projects

@manticore-projects This is not quite right, since SpecialStringFunctionWithNamedParameters with NamedExpressionListExprFirst and the following is able to accept e.g. substring( a from b). This way the extract should be accepted as well.

This is parsed

select EXTRACT(DAY FROM (SYSDATE - to_date('20180101', 'YYYYMMDD' ) ) ) from dual;

So maybe this DAY TO SECONDS can be implemented this way as well.

wumpz avatar May 04 '23 21:05 wumpz

In my opinion, this particular production NamedExpressionListExprFirst is cursed (since it depends on a semantic LOOKAHEAD) and should be replaced with a proper implementation of the SQL:2016 standard functions. I did convert() and trim() already and will do the others next.

NameExpressionList must die (although I have tamed it already by streamlining it into an extension of ExpressionList).

manticore-projects avatar May 04 '23 21:05 manticore-projects

@manticore-projects :) You are right, it was a hack, but since you already started discussing a new version, isn't that a bit to much? The lookahead here is not that bad, since it is drastically filtered by this function name list.

wumpz avatar May 04 '23 22:05 wumpz

I leave it to you to decide. In the current development stage it extends ExpressionList and so fits in much better. However, I consider it a kind of generic fallback, while I still would provide the SQL:2016 compliant functions separately.

(It's a shame that SQL standard allowed those syntax, when regular functions with comma separated parameters would have done a fine job.)

manticore-projects avatar May 04 '23 22:05 manticore-projects