prql icon indicating copy to clipboard operation
prql copied to clipboard

Window functions in filter, sort & join

Open aljazerzen opened this issue 2 years ago • 0 comments

from tbl1
filter (average bar) > 3

... produces:

WITH table_0 AS (
  SELECT
    tbl1.*
  FROM
    tbl1
)
SELECT
  table_0.*
FROM
  table_0
WHERE
  AVG(bar) OVER () > 3

... which uses window function in WHERE, which is not allowed. The window function should have been applied in first CTE and used only in SELECT in the second CTE.

I know average does not make sense in filter, but there could be lag or rank instead.

aljazerzen avatar Jul 11 '22 10:07 aljazerzen