You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SELECT foo.id AS foo_id loses Go type information #606
I'm trying to use custom Go types for some SQL columns, mapping a sql int64 to Go type FooID uint64.
It seems I can have
SELECT foo.id FROM ... and get generated type FooRow struct { ID FooID }
or I can have
SELECT foo.id AS foo_id FROM ... and get type FooRow struct { FooID int64 }
but I cannot get both at the same time. Using the AS forgets the association with the Go type, but without the AS my struct fields are kinda misleading. Consider SELECT foo.id, bar.id FROM ..., can't have two things fighting for the struct field name ID.
@tv42 Can you provide a complete example for this issue? Since this involves type overrides, can you include a sqlc configuration file, database schema, and example queries.
$ go generate
$ grep -A 1 'type Bad' query.sql.go
type BadNameRow struct {
ID sqlc_issues606_reproducer.UserID
--
type BadTypeRow struct {
UserID int64
I've personally tested this one with sqlc v1.13.0 and with type overrides this can be easily worked around. Could that solve it @tv42 ?
Sorry that's too vague to say much. The reproducing example already uses type overrides to switch from an int64 to UserID, do you think it is somehow wrong?
Activity
kyleconroy commentedon Aug 28, 2021
@tv42 Can you provide a complete example for this issue? Since this involves type overrides, can you include a sqlc configuration file, database schema, and example queries.
tv42 commentedon Aug 31, 2021
Here's a full repro with the latest versions: https://gist.github.com/tv42/34d87e0975739f20654eac4894380511
To summarize:
How it goes wrong:
tv42 commentedon Sep 8, 2021
Can you please re-open this? It's still there, as the previous comment shows.
kyleconroy commentedon Sep 8, 2021
@tv42 whoops, sorry about that. Thanks for writing up the full example.
alarbada commentedon Apr 5, 2022
I've personally tested this one with sqlc v1.13.0 and with type overrides this can be easily worked around. Could that solve it @tv42 ?
tv42 commentedon Apr 19, 2022
Sorry that's too vague to say much. The reproducing example already uses type overrides to switch from an
int64toUserID, do you think it is somehow wrong?The bug seems to be that using
SELECT column_name AS aliasmakes the type overrides not be applied.