prql
prql copied to clipboard
Date diff with `-` operator
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')
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})"