[#7518] Add support for parsing DATEDIFF(d1, d2)
This commit is contained in:
parent
dc523e4772
commit
809286d325
@ -655,6 +655,7 @@ term =
|
||||
| 'CURTIME' '(' ')'
|
||||
| dateLiteral
|
||||
| 'DATEADD' '(' datePart ',' field ',' field ')'
|
||||
| 'DATEDIFF' '(' [ datePart ',' ] field ',' field ')'
|
||||
| 'DATE_TRUNC' '(' stringLiteral ',' field ')'
|
||||
| 'DAY' '(' field ')'
|
||||
| 'DAYOFMONTH' '(' field ')'
|
||||
|
||||
@ -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));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user