Skip to content

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
alfonsodev pushed a commit to ExponentiaTeam/sqlc that referenced this pull request Oct 13, 2025
* fix(engine/sqlite): fixed IN operator precedence

close sqlc-dev#2368

* test: add endtoend

* chore: v1.19.1

* Regenerate parser

---------

Co-authored-by: Kyle Conroy <kyle@sqlc.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants