prql icon indicating copy to clipboard operation
prql copied to clipboard

Date diff with `-` operator

Open max-sixty opened this issue 2 years ago • 1 comments

From @matsonj: https://twitter.com/matsonj/status/1537969665070092295

Currently we don't handle this, but I think we could without that much trouble:

derive x = @2022-01-01 - @2021-01-01
SELECT
  DATE '2022-01-01' - DATE '2021-01-01' AS x

...should be DATEDIFF(DATE '2022-01-01', DATE '2021-01-01')

max-sixty avatar Jun 18 '22 03:06 max-sixty

Great point, i agree

This should be implemented more generally via "operator overloading" aka some way of declaring what to do when a binary (or even unary) operation is applied to two arbitrary types:

maybe something like:

operation - a<date> b<date> -> s"DATEDIFF(DATE ${a}, DATE ${b})"

aljazerzen avatar Jun 18 '22 15:06 aljazerzen