prql icon indicating copy to clipboard operation
prql copied to clipboard

Preventing single-equals-sign errors in filters

Open mklopets opened this issue 2 years ago • 1 comments

I think using a single = sign in a filter operation should result in an error. SQL uses single-equals for comparison (plus people make typos), which means you can easily type up the following:

from x
filter left_side = right_side

I could be wrong, but I seem to remember this erroring at some point in the past. Now, it happily compiles to:

SELECT
  *
FROM
  x
WHERE
  right_side

Furthermore, if right_side was instead right in PRQL, then the compiled SQL would instead contain WHERE "right".

I thought for a second that the compiler genuinely assigned the value of right_side to the variable left_side here, but it doesn't, because:

from x
filter something = right_side
select something

compiles to

SELECT
  something
FROM
  x
WHERE
  right_side

instead of

SELECT
-  something
+  right_side
FROM
  x
WHERE
  right_side

mklopets avatar Jan 05 '23 20:01 mklopets

Yes agree, this should be an error

max-sixty avatar Jan 05 '23 20:01 max-sixty