prql icon indicating copy to clipboard operation
prql copied to clipboard

Support IN set of values

Open Baoqi opened this issue 3 years ago • 4 comments

Currently, seems the only supported "in" is like:

from employees
filter (age | in 20..80)

which will be translated to:

SELECT
  employees.*
FROM
  employees
WHERE
  age BETWEEN 20
  AND 80

Is there a way for IN Clause, like:

SELECT
  employees.*
FROM
  employees
WHERE
  dept IN ('tech', 'hr', 'sales')

Baoqi avatar Jul 01 '22 07:07 Baoqi

Good point.

I propose following syntax:

from employees
filter (dept | in ['tech', 'hr', 'sales'])

There is quite a lot of punctuation, WDYT?

aljazerzen avatar Jul 01 '22 10:07 aljazerzen

I think that's good!

Does this compile to the same SQL for most dialects?

max-sixty avatar Jul 01 '22 13:07 max-sixty

Yes, I think

dept IN ('tech', 'hr', 'sales')

in SQL is supported by most dialects

Baoqi avatar Jul 02 '22 02:07 Baoqi

Great. We'd need to work out a way of distinguishing based on the type of the arg from the stdlib, which isn't yet supported, but could be supported by #593.

If that's difficult, we could add it into the compiler, which would be fairly easy-ish™

max-sixty avatar Jul 02 '22 04:07 max-sixty

Duplicate of https://github.com/PRQL/prql/issues/993 and fixed in https://github.com/PRQL/prql/pull/3883

PrettyWood avatar Dec 08 '23 08:12 PrettyWood