Skip to content

IN and NOT IN with arrays #109

Closed
Closed

Description

@tobia

When the left-hand side argument of IN / NOT IN is an array, the operator checks whether ANY value in the array is present / absent from the right-hand side argument.

This is not a bad choice, but the documentation says:

This is somewhat illogical, but it is convenient for implementing certain Yandex.Metrica functionality.
[...] 
This is completely illogical, so don't rely on this behavior. We recommend using higher-order functions instead.

Instead of recommending people not to use it, I propose the following roadmap of changes, to increase the readability and usefulness of this feature:

Step 1. Accept and ignore (no changes needed to the query engine) an ANY keyword before IN / NOT IT and change the documentation to recommend people use it when the left argument is an array.

Example: [1, 2, 3] ANY IN (3, 4, 5) and [1, 2, 3] ANY NOT IN (3, 4, 5)

This would make it clear what the operator does, so there's no need to call it "illogical" anymore.

Step 2. Add support for an ALL keyword before IN / NOT IN that performs the check on all elements of the array.

Example: [1, 2, 3] ALL IN (3, 4, 5) and [1, 2, 3] ALL NOT IN (3, 4, 5)

This would cover most use cases and be much faster than using a higher-order function.

Activity

  1. alexey-milovidov commented on Sep 13, 2016

    @alexey-milovidov
    Member

    Thank you for suggestion!

    By the way, there is already a way to specify it explicitly:
    arrayExists(x -> x IN (3, 4, 5), [1, 2, 3])
    and
    arrayAll(x -> x IN (3, 4, 5), [1, 2, 3])

    Implementation of ANY IN, ALL IN operators is possible, but I doubt, do we really need to extend syntax for this special case.

  2. added a commit that references this issue on Apr 6, 2022
  3. added 4 commits that reference this issue on Feb 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions