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
will generate different response structs (something like GetByBarValueRow and GetByFooValueRow), however by meaning it's the same objects.
I tried to use rename field in configuration but it didn't help. I quickly checked the source code and looks like there is no way to set the output type.
Is it possible to add something like:
use rename also for queries types or
(IMHO it's better) add an annotation to queries like name: GetByVarValue :type FooBar :many
In this example, I get back a PostGetManyRow and a PostsGetByTastyRow for two given queries. These structs are identical except in name. And constantly type asserting them at each call site clutters the code and is tedious.
I thought that maybe the example in embedding structs might solve the issue, but I still get two differently named types for each query.
Any thoughts on this?
Perhaps a configuration option to merge identical structs? Or a paramter in the --name: declaration that enables a merge behavior?
Question:
Why can't we always use the actual model instead of creating separate row structs for each query?
Go will use the default values when some of the fields are not present, and leave it for the user to decide/manage the conversion of the models -> entity/domain objects
For e.g.
If I have user table in db with fields: id, name, email, hash, created_at, and have two different select queries that return different fields from the user, sqlc can still scan the db result into the User struct, and this model struct will then be managed by the user
I think I'll use jinzhu/copier (to copy row struct into model struct) till this issue gets resolved. This is a great project, and am still learning. If I can contribute somehow, plz do let me know.
Activity
allochi commentedon Jan 22, 2023
This is exactly what we are looking for in our project, unfortunately it's holding us back from using SQLC, is this in the pipeline?
kyleconroy commentedon Sep 22, 2023
Also related to #755
[-](Re)Name query return type[/-][+]Override query return type[/+]swetjen commentedon Mar 6, 2024
I'd like to comment I have the same issue.
In this example, I get back a
PostGetManyRowand aPostsGetByTastyRowfor two given queries. These structs are identical except in name. And constantly type asserting them at each call site clutters the code and is tedious.I thought that maybe the example in embedding structs might solve the issue, but I still get two differently named types for each query.
Any thoughts on this?
Perhaps a configuration option to merge identical structs? Or a paramter in the
--name:declaration that enables a merge behavior?Would the team be open to a PR to fix this?
kahunacohen commentedon Jun 26, 2024
Is anybody working on this? I might be willing to issue a PR, if someone leads me in the right direction...
phoenisx commentedon Oct 26, 2025
Question:
Why can't we always use the actual model instead of creating separate row structs for each query?
Go will use the default values when some of the fields are not present, and leave it for the user to decide/manage the conversion of the models -> entity/domain objects
For e.g.
If I have
usertable in db with fields:id, name, email, hash, created_at, and have two different select queries that return different fields from the user, sqlc can still scan the db result into theUserstruct, and this model struct will then be managed by the userI think I'll use
jinzhu/copier(to copy row struct into model struct) till this issue gets resolved. This is a great project, and am still learning. If I can contribute somehow, plz do let me know.LucaCerina commentedon Sep 8, 2026
+1
I have a similar issue with two simple queries
Which generates two structs
GetPersonRowandGetPersonsRowdespite being the same struct.There is a mention of this not being an issue in stackoverflow for version 1.17.0. Is that a fluke?