time is hard...

This commit is contained in:
Christian De la Hoz 2021-08-31 20:30:45 +02:00
parent 86d51a3d6c
commit 117d416300
2 changed files with 48 additions and 1 deletions

View file

@ -244,3 +244,37 @@ SELECT
(identifier)
(comparison_null)))))
================================================================================
time expressions
================================================================================
SELECT
foo::interval,
foo at time zone 'utc',
interval '1 day',
interval '1' hour to second,
interval '1' day + interval '3' month;
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(op_expression
(identifier)
(cast)
(identifier)))
(select_item
(time_expression
(identifier)
(string)))
(select_item
(time_expression
(string)))
(select_item
(time_expression
(string)))
(select_item
(op_expression
(time_expression
(string))
(time_expression
(string))))))

View file

@ -741,6 +741,19 @@ module.exports = grammar({
time_expression: $ => choice(
seq($.identifier, kw("at"), kw("time"), kw("zone"), $._value_expression),
// TODO(chrde): this is plain wrong - https://www.postgresql.org/docs/13/datatype-datetime.html
seq(kw("interval"), $.string, optional($._interval_fields)),
),
_interval_fields: $ => choice(
kw("year"), kw("month"), kw("day"), kw("hour"), kw("minute"), kw("second"),
seq(kw("year"), kw("to"), kw("month")),
seq(kw("day"), kw("to"), kw("hour")),
seq(kw("day"), kw("to"), kw("minute")),
seq(kw("day"), kw("to"), kw("second")),
seq(kw("hour"), kw("to"), kw("minute")),
seq(kw("hour"), kw("to"), kw("second")),
seq(kw("minute"), kw("to"), kw("second")),
),
function_call: $ => seq(
@ -754,7 +767,7 @@ module.exports = grammar({
),
op_expression: $ => choice(
prec.left(12, seq($._value_expression, $.cast, $._value_expression)),
prec.left(12, seq($._value_expression, $.cast, $.identifier)),
// array access
prec.right(10, seq(choice($.minus, $.plus), $._value_expression)),
// ^