Skip to content

GROUP BY clause doesn't accept column aliases #1363

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

Closed
TiagoVentosa opened this issue Dec 28, 2021 · 3 comments
Closed

GROUP BY clause doesn't accept column aliases #1363

TiagoVentosa opened this issue Dec 28, 2021 · 3 comments

Comments

@TiagoVentosa
Copy link

Version

1.11.0

What happened?

when a query is done with an alias in a select column and there is a group by clause using the alias, the code generation fails. This issue seems to be related with #1285

Relevant log output

column reference "alias" not found

Database schema

-- Example queries for sqlc
CREATE TABLE authors (
  id   BIGSERIAL PRIMARY KEY,
  name text      NOT NULL,
  bio  text,
  type text      NOT NULL
);

SQL queries

-- name: countWithCondition :many
SELECT CASE WHEN type = 'DECEASED' then false ELSE true END as alias, count(*) FROM authors
GROUP BY alias;

Configuration

{
  "version": "1",
  "packages": [
    {
      "path": "db",
      "engine": "postgresql",
      "schema": "query.sql",
      "queries": "query.sql"
    }
  ]
}

Playground URL

https://play.sqlc.dev/p/3000f866b2534e1ea7cb0d107056a8ff20b8eddf5dbc0c748710c2a905afb98f

What operating system are you using?

macOS

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

@TiagoVentosa TiagoVentosa added bug Something isn't working triage New issues that hasn't been reviewed labels Dec 28, 2021
@Hworden
Copy link

Hworden commented Dec 29, 2021

@Hworden
Copy link

Hworden commented Dec 30, 2021

@TiagoVentosa hey I just built this from source and I don't see the error, however, when I go to version v1.11.0 (commit ad53cfe) I see the error you mentioned. So seems as though between the latest commit and version v1.11.0 the issue was fixed.

I'm attaching the results of sqlc when I build from source using the details you provided.

results.zip

@TiagoVentosa
Copy link
Author

@Hworden thanks for the feedback, and sorry for taking so long.

From the results that you've sent, it seems it has been fixed in the latest commit then. I suppose it will be available in the next version.

Thank you

@kyleconroy kyleconroy added 📚 postgresql 💻 darwin 🔧 golang and removed triage New issues that hasn't been reviewed labels Jan 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants