Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/sqlcPublic
forked fromsqlc-dev/sqlc

Track scope for CTEs to fix ambiguous column bug#1

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
mafredri wants to merge1 commit intomain
base:main
Choose a base branch
Loading
frommafredri/fix-ambiguous-column

Conversation

@mafredri
Copy link
Member

@mafredrimafredri commentedOct 29, 2025
edited
Loading

While adding a simple EXISTS condition, I ran into an sqlc bug because it wasn't tracking scope for CTEs.

query.sql:11:20: column reference "owner_id" is ambiguousquery.sql:24:20: column "w_owner_id" does not existquery.sql:38:20: column reference "owner_id" is ambiguous

The query could look something like this:

WITH cteAS (SELECT owner_idFROM table_with_owner_idWHERE EXISTS (SELECT1FROM another_table_with_owner_id))SELECT*FROM cte;

Test queries have been added that reproduce the bug.

Some of the existing testdata also had to be updated because the tracking got improved.

Go installable branch:https://github.com/coder/sqlc/tree/mafredri/fix-ambiguous-column.import

CGO_ENABLED=1 go install github.com/coder/sqlc/cmd/sqlc@aab4e865a51df0c43e1839f81a9d349b41d14f05

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.


Upstreamsqlc-dev#4159

mafredri added a commit to coder/coder that referenced this pull requestOct 29, 2025
mafredri added a commit to coder/coder that referenced this pull requestOct 29, 2025
@mafredrimafredriforce-pushed themafredri/fix-ambiguous-column branch 5 times, most recently from5f67321 to7c1a82bCompareOctober 29, 2025 12:09
mafredri added a commit to coder/coder that referenced this pull requestOct 29, 2025
mafredri added a commit to coder/coder that referenced this pull requestOct 29, 2025
)
SELECT *
FROM wtask
ORDER BY CASE WHEN w_owner_id = @owner_id THEN 0 ELSE 1 END;
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Review: Why didn't I just use this workaround?

Because the CTE wasn't indexed and as such, unknown columnw_owner_id.

mafredri added a commit to coder/coder that referenced this pull requestOct 29, 2025
mafredri added a commit to coder/coder that referenced this pull requestOct 29, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

1 participant

@mafredri

[8]ページ先頭

©2009-2025 Movatter.jp