Skip to content

Conversation

@andrewmbenton
Copy link
Collaborator

Resolves #1886
Resolves #2398
Resolves #2399

@andrewmbenton
Copy link
Collaborator Author

andrewmbenton commented Jul 27, 2023

I think this resolves the referenced issues and pull request, but there is still a subtle bug (not new). The following query runs fine with psql but sqlc still gets confused even with the patch in this PR applied.

SELECT a.name AS name
FROM authors a JOIN authors b ON a.id = b.id
ORDER BY name;

Here's a playground link for v1.19.1: https://play.sqlc.dev/p/8648bbce740f0f059549e4e50e75bd073443080be5e5d12fd68aa5699f1b0c72

I think I'll create a new issue for this unless I can resolve it quickly.

@akutschera
Copy link
Contributor

FWIW, let's merge this one instead of #2399. Just my 2c

@kyleconroy kyleconroy merged commit 7d6377f into main Jul 28, 2023
@kyleconroy kyleconroy deleted the andrew/fix-order-by-with-alias branch July 28, 2023 16:41
alfonsodev pushed a commit to ExponentiaTeam/sqlc that referenced this pull request Oct 13, 2025
… joins (sqlc-dev#2537)

* fix(compiler): correctly validate alias in order/group by clauses for joins

Resolves sqlc-dev#1886
Resolves sqlc-dev#2398
Resolves sqlc-dev#2399

* remove dead code and split up test
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.

incorrect ambiguous reference check [PostgresSQL] Failure to use GROUP BY for column output names when using subqueries

4 participants