← 输入框|github.com|刷新
Skip to content

Pass the HAVING context to ALL / ANY / SOME subqueries to close #2855 - #2920

Merged
mathiasrw merged 1 commit into
AlaSQL:developfrom
komal0000:fix/having-all-subquery
Oct 29, 2026
Merged

mathiasrw merged 1 commit into
AlaSQL:developfrom
komal0000:fix/having-all-subquery

Conversation

@komal0000

Copy link
Copy Markdown
Contributor

Fixes #2855

Problem

HAVING ... > ALL (subquery) threw ReferenceError: p is not defined, as did ANY and SOME:

SELECT a, COUNT(*) AS c FROM t1 GROUP BY a
HAVING COUNT(*) > ALL (SELECT COUNT(*) FROM t2 WHERE t2.a > 5)

The same comparison in WHERE works.

Cause

In src/50expression.js, the code for x op ALL (subquery) and x op ANY|SOME (subquery) always called the subquery with a variable named p. p is the row variable in WHERE, but HAVING compiles with g, so p is undefined there. IN and NOT IN already pass ${context}, which is why they work in HAVING.

Fix

The ALL and ANY/SOME branches pass ${context}, the same as IN. In WHERE the context is still p, so the generated code there doesn't change.

Tests

New test/test2855.js:

  • the issue's query, plus a > ALL (...) in HAVING
  • > ANY and = SOME in HAVING
  • ALL and ANY in WHERE, which should give the same results as before

Results:

  • Without the change in src/, the two HAVING tests fail with ReferenceError: p is not defined.
  • With the change: bun test --preload ./test/bun-setup.js ./test/test2855.js → 3 passed.
  • Full suite → 2516 passed, 9 failed. The same 9 tests (test 107-B Excel and CLI) fail on clean develop on my Windows machine.

@mathiasrw

Copy link
Copy Markdown
Member

Short and precise. Love it. Than you!

@mathiasrw
mathiasrw merged commit 02fae0d into AlaSQL:develop Oct 29, 2026
10 checks passed
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.

HAVING ... > ALL (subquery) throws ReferenceError: p is not defined

2 participants