Skip to content

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

Closed
@voluntas

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

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