Skip to content

fix(builder): resolve aggregate aliases inside having logical groups - #23

Closed
abnegate wants to merge 1 commit into
0.8.xfrom
fix/having-logical-aliases
Closed

abnegate wants to merge 1 commit into
0.8.xfrom
fix/having-logical-aliases

Conversation

@abnegate

@abnegate abnegate commented Dec 1, 2026

Copy link
Copy Markdown
Member

What does this PR do?

Backports the HAVING fix from appwrite/appwrite#16353 (Rust extension) to the pure-PHP 0.8 builder, for a 0.8.1 release.

Conditions nested in and()/or() inside having() were compiled with the bare alias (HAVING (\total` > ? OR `total` < ?)), which only MySQL accepts. They now resolve to the aggregate expression at any depth (HAVING (COUNT() > ? OR COUNT() < ?)`), matching top-level having conditions.

0.8.x was cut from tag 0.8.0, since main is now the monorepo mirror and 0.9 requires the extension.

Test Plan

🤖 Generated with Claude Code

Conditions nested in and()/or() compiled with the bare alias, which Postgres and ClickHouse reject in HAVING. Aliases now resolve to the aggregate expression at any depth.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@appwrite

appwrite Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Code review

Commit Status Tier Verdict Details
f5b1ecc Reviewed Reviewed 🟢 S · Ready to merge ✅ Approved View review

The recursive compilation preserves existing handling for non-alias conditions and correctly resolves aliases through nested logical groups.

The builder now recursively compiles AND/OR groups in HAVING, resolving aggregate aliases to their underlying expressions at every nesting level. The tests update SQL expectations and cover nested alias resolution and empty logical groups in PostgreSQL.

Walkthrough (4)
File Change
src/Builder.php Recursively compiles logical HAVING groups and resolves aggregate aliases in their leaf conditions.
tests/Builder/ClickHouseTest.php Updates the nested HAVING expectation to use the aggregate expression.
tests/Builder/MySQLTest.php Updates nested HAVING expectations to use aggregate expressions.
tests/Builder/PostgreSQLTest.php Adds nested alias-resolution and empty-logical-group HAVING regressions.

Reviewed f5b1ecc

Tip

Comment @appwrite review to re-run, or mention @appwrite with a question.

@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown

Thanks for contributing! This repository is a read-only mirror; development for this library happens in packages/query in appwrite/appwrite. Please open this pull request there instead.

@github-actions github-actions Bot closed this Dec 1, 2026

@appwrite appwrite Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Tier S · Looks good to merge. Summary

@abnegate
abnegate deleted the fix/having-logical-aliases branch December 1, 2026 01:16
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.

1 participant