Repository navigation
Conversation
mafredri
force-pushed
the
mafredri/fix-ambiguous-column
branch
5 times, most recently
from
October 29, 2025 12:09
5f67321 to
7c1a82b
Compare
mafredri
added a commit
to coder/coder
that referenced
this pull request
Oct 29, 2025
Refs coder/sqlc#1 Unblocks #20501 Upstream sqlc-dev/sqlc#4159
mafredri
added a commit
to coder/coder
that referenced
this pull request
Oct 29, 2025
Refs coder/sqlc#1 Unblocks #20501 Upstream sqlc-dev/sqlc#4159
This pulls in 78 upstream commits since coder/sqlc's prior fork point (b807fe9), most importantly: * sqlc-dev#4390: strip \restrict / \unrestrict psql meta-commands from schema files (fixes sqlc-dev#4065 / coder/internal#965). * sqlc-dev#4378: upgrade Go toolchain to 1.26.2. * Various dependency bumps and parser improvements. Conflict resolution: * All content conflicts were import-path collisions — our renamed imports (github.com/coder/sqlc) versus upstream's additions of new sqlc-dev/sqlc imports. Resolved by taking upstream's side, then re-applying the global rename across .go and go.mod files (including newly-added upstream files that auto-merged). * internal/sqltest/pgx.go: accepted upstream deletion (removed in sqlc-dev#4379, 'Remove github.com/jackc/pgx/v4 dependency').
mafredri
force-pushed
the
mafredri/fix-ambiguous-column
branch
from
November 13, 2026 17:10
7c1a82b to
7a30c2e
Compare
mafredri
added a commit
to coder/sqlc
that referenced
this pull request
Nov 13, 2026
A subquery inside a CTE made sqlc resolve column references in that CTE, and in CTEs selecting from it, against the subquery's tables too. Valid queries then failed to generate with false positives such as `column reference "owner_id" is ambiguous` or `column "w_owner_id" does not exist`. Track the CTE each reference belongs to when resolving columns and parameters. Parameters inside a CTE, or compared against a CTE column, now get the referenced type instead of a nullable fallback: cte_left_join and cte_update generate string, bool and int64 where they generated pgtype.Text, pgtype.Bool and pgtype.Int8. The fix previously lived only on the mafredri/fix-ambiguous-column.import branch that coder/coder pinned. It never reached main, so coder/coder lost it when it moved its pin to main's merge of upstream v1.31.1 (#6). The upstream PR, sqlc-dev#4159, is still open.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
EDIT: Sorry, I did not intend to open this PR over here yet, it was meant for
coder/sqlc. But since it's here already. I'll keep it open.While adding a simple EXISTS condition, I ran into an sqlc bug because it wasn't tracking scope for CTEs.
The query could look something like this:
Test queries have been added that reproduce the bug.
Some of the existing testdata also had to be updated because the tracking got improved.
This bug was initially solved via Coder Tasks (Claude Code), but the solution was messy and followed the "throw code at it until it works", as such it has been mostly rewritten.