Skip to content

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

Closed

Description

@voluntas

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

Activity

  1. added
    bugSomething isn't working
    triageNew issues that hasn't been reviewed
    on Oct 7, 2022
  2. added a commit that references this issue on Jul 1, 2023
  3. added a commit that references this issue on Jul 27, 2023
    5bd0257
  4. added a commit that references this issue on Jul 28, 2023
    7d6377f
  5. added a commit that references this issue on Oct 13, 2025
    219e197
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions