[#7518] Add support for parsing DATEDIFF(d1, d2)

This commit is contained in:
Lukas Eder 2018-09-26 11:42:10 +02:00
parent dc523e4772
commit 809286d325
2 changed files with 17 additions and 0 deletions

View File

@ -655,6 +655,7 @@ term =
| 'CURTIME' '(' ')'
| dateLiteral
| 'DATEADD' '(' datePart ',' field ',' field ')'
| 'DATEDIFF' '(' [ datePart ',' ] field ',' field ')'
| 'DATE_TRUNC' '(' stringLiteral ',' field ')'
| 'DAY' '(' field ')'
| 'DAYOFMONTH' '(' field ')'

View File

@ -4530,6 +4530,8 @@ final class ParserImpl implements Parser {
return field;
else if ((field = parseFieldDateAddIf(ctx)) != null)
return field;
else if ((field = parseFieldDateDiffIf(ctx)) != null)
return field;
if (N.is(type))
if ((field = parseFieldDenseRankIf(ctx)) != null)
@ -5504,6 +5506,20 @@ final class ParserImpl implements Parser {
return null;
}
private static final Field<?> parseFieldDateDiffIf(ParserContext ctx) {
if (parseFunctionNameIf(ctx, "DATEDIFF")) {
parse(ctx, '(');
Field<Date> d1 = (Field<Date>) parseField(ctx, Type.D);
parse(ctx, ',');
Field<Date> d2 = (Field<Date>) parseField(ctx, Type.D);
parse(ctx, ')');
return DSL.dateDiff(d1, d2);
}
return null;
}
private static final Date parseDateLiteral(ParserContext ctx) {
try {
return Date.valueOf(parseStringLiteral(ctx));