Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(engine/sqlite): fixed IN operator precedence #2428

Merged
merged 5 commits into from
Jul 24, 2023

Conversation

orisano
Copy link
Contributor

@orisano orisano commented Jul 10, 2023

close #2368

In ANTLR, the alternative defined first has a higher precedence.
Because the precedence of the IN operator was lower than that of AND, what should have been interpreted as A was interpreted as B.

A:

DELETE FROM
  books AS b
WHERE
  ( b.author NOT IN (
    SELECT
      a.name
    FROM
      authors a
    WHERE
      a.age >= ?
  ) )
  AND ( b.translator NOT IN (
    SELECT
      t.name
    FROM
      translators t
    WHERE
      t.age >= ?
  ) )
  AND b.year <= ?;

B:

DELETE FROM
  books AS b
WHERE
  ( b.author NOT IN (
    SELECT
      a.name
    FROM
      authors a
    WHERE
      a.age >= ?
  )
  AND b.translator ) NOT IN (
    SELECT
      t.name
    FROM
      translators t
    WHERE
      t.age >= ?
  )
  AND b.year <= ?;

This has been corrected by defining the IN operator alternative before AND.

@orisano orisano force-pushed the fix/in-operator-precedence branch from 729cda6 to b11b015 Compare July 15, 2023 15:36
@kyleconroy
Copy link
Collaborator

Since a few of these PRs touch the same generated code, I'm merging them in one at a time after merging in main.

@kyleconroy kyleconroy merged commit 5ffe722 into sqlc-dev:main Jul 24, 2023
7 checks passed
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sqlite engine creates wrong number of arguments in case of several JOINS with parameters
3 participants