Skip to content

Using composite keys in where clause #14977

Open

Description

@nsychev

Issue Creation Checklist

  • I understand that my issue will be automatically closed if I don't fill in the requested information
  • I have read the contribution guidelines

Feature Description

Describe the feature you'd like to see implemented

Assume we have table people containing two rows:

first_name last_name occupation
John Smith Engineer
Elroy Adams Writer

I can do this in Postgres:

DELETE FROM users WHERE (first_name, last_name) IN (('John', 'Smith'), ('Elroy', 'Adams'));

I'm able to do the same thing using Sequelize when index is simple (like where: { id: { [Op.in]: [1, 2, 3] } }, but for composite indexes it fails.

Describe why you would like this feature to be added to Sequelize

I'd like to somehow, for example, delete many records based on composite key.

Is this feature dialect-specific?

  • No. This feature is relevant to Sequelize as a whole.
  • Yes. This feature only applies to the following dialect(s):

Would you be willing to resolve this issue by submitting a Pull Request?

  • Yes, I have the time and I know how to start.
  • Yes, I have the time but I will need guidance.
  • No, I don't have the time, but my company or I are supporting Sequelize through donations on OpenCollective.
  • No, I don't have the time, and I understand that I will need to wait until someone from the community or maintainers is interested in implementing my feature.

P.S. I'll try to find some time, but I'm unsure about it


Indicate your interest in the addition of this feature by adding the 👍 reaction. Comments such as "+1" will be removed.

Activity

  1. added
    type: feature
    on Sep 17, 2022
  2. ephys commented on Sep 17, 2022

    @ephys
    Member

    The first step would be to determine what the API would look like. We need to be able to specify multiple columns & tuples.

    The main issue is that [] can be interpreted as both a tuple, and a postgres array.

    A tuple API could help disambiguate this:

    where(
      tuple(col('firstName'), col('lastName')),
      Op.in,
      [tuple('john', 'doe'), tuple('john', 'smith')],
    )

    which would result in

    ("firstName", "lastName") IN (('john', 'doe'), ('john', 'smith'))
  3. 10raw commented on Oct 2, 2022

    @10raw

    Hey I would like to give a try on this issue. May I be assigned with the same?

  4. WikiRik commented on Oct 2, 2022

    @WikiRik
    Member

    @10raw sure, go ahead! Feel free to ask questions when you have them

  5. ephys commented on Mar 2, 2023

    @ephys
    Member

    This is likely implemented by #15598, but a future PR will add a test to make sure

  6. added theissue type on Mar 9, 2025
  7. removed
    type: feature
    on Mar 9, 2025
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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions