Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PostgresSQL] Failure to use GROUP BY for column output names when using subqueries #1886

Closed
voluntas opened this issue Oct 7, 2022 · 0 comments · Fixed by #2537
Closed

Comments

@voluntas
Copy link

voluntas commented Oct 7, 2022

Version

1.15.0

What happened?

When using a subquery, if I specify an output column name for GROUP BY, sqlc cannot compile it. if I execute SQL directly, it works fine.

I am aware that when using PostgreSQL, column output names can be specified as GROUP BY. However, if I am mistaken, please let me know.

Relevant log output

No response

Database schema

CREATE TABLE spam (
    id SERIAL PRIMARY KEY
);

SQL queries

-- name: Spam :many
SELECT
  s.id AS "s_id"
FROM
  -- Using subqueries doesn't work.
  (
    SELECT
      spam.id
	FROM spam
  ) AS "s"
-- Change this to s.id and it will work.
GROUP BY s_id;

Configuration

No response

Playground URL

https://play.sqlc.dev/p/b3ae0c313bd30c061316dc729e285eba780ba4c7c94e4a44eaac81c619ce9c99

What operating system are you using?

macOS

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

@voluntas voluntas added bug Something isn't working triage New issues that hasn't been reviewed labels Oct 7, 2022
@kyleconroy kyleconroy added 📚 postgresql 💻 darwin 🔧 golang and removed triage New issues that hasn't been reviewed labels Nov 9, 2022
akutschera added a commit to akutschera/sqlc that referenced this issue Jul 1, 2023
Alias column names don't exist in the table definition. When we take
it from the select target list, we only need to do this once (and not
once for every table in a join statement).

Refs: sqlc-dev#2398 sqlc-dev#1886
andrewmbenton added a commit that referenced this issue Jul 27, 2023
kyleconroy pushed a commit that referenced this issue Jul 28, 2023
… joins (#2537)

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

Resolves #1886
Resolves #2398
Resolves #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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants