We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
1.14.0
The proper generated row should be
type GetAuthorRow struct { ID int64 Name string } // instead of type GetAuthorRow struct { ID int64 Name string ID_2 int64 Name_2 string Bio sql.NullString }
The * should take only columns from the subquery and not the whole table and subquery at the same time.
*
-
-- Example queries for sqlc CREATE TABLE authors ( id BIGSERIAL PRIMARY KEY, name text NOT NULL, bio text );
-- name: GetAuthor :one select distinct on (row.id) * from ( select a.id, a.name from authors a ) as row;
{ "version": "1", "packages": [ { "path": "db", "engine": "postgresql", "schema": "query.sql", "queries": "query.sql" } ] }
https://play.sqlc.dev/p/2292f29b8a05fb2f8b8ce2993849db633c6c03424af01bf8582bf2264419f1c9
Linux
PostgreSQL
Go
The text was updated successfully, but these errors were encountered:
This is the only workaround I found to get the proper results. https://play.sqlc.dev/p/c42b9c650b6b24cf1a9cf2fb91c31aec17753f270e0cdef31da28f8b955d70a1
But it actually doesn't run on PSQL 14
psq # select row.id, row.name from ( select distinct on (row.id) * from ( select a.id, a.name from authors a ) as row ) as t; ERROR: missing FROM-clause entry for table "row" LINE 2: row.id,
and using CTE it returns error - column reference "id" is ambiguous
column reference "id" is ambiguous
Sorry, something went wrong.
Another workaround is to specify the exact columns you want in the query
-- name: GetAuthor :one select distinct on (row.id) row.id, row.name from ( select a.id, a.name from authors a ) as row;
This generates the expected struct
type GetAuthorRow struct { ID int64 Name string }
Successfully merging a pull request may close this issue.
Version
1.14.0
What happened?
The proper generated row should be
The
*
should take only columns from the subquery and not the whole table and subquery at the same time.Relevant log output
Database schema
SQL queries
Configuration
Playground URL
https://play.sqlc.dev/p/2292f29b8a05fb2f8b8ce2993849db633c6c03424af01bf8582bf2264419f1c9
What operating system are you using?
Linux
What database engines are you using?
PostgreSQL
What type of code are you generating?
Go
The text was updated successfully, but these errors were encountered: