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
Cast query result to existing type instead of creating a new one #2252
-- name: SelectOneFileByID :one SELECTf.id, f.name, b.sizeFROM file f
JOIN blob b
ONf.blob_id==b.idWHEREf.id== $1;
-- name: SelectOneFileByName :one SELECTf.id, f.name, b.sizeFROM file f
JOIN blob b
ONf.blob_id==b.idWHEREf.name== $1;
This will generate two structs in Go:
SelectOneFileByID
SelectOneFileByName
I want single type: SelectOneFile because struct's generated by sqlc are of same shape, no need to generate data-type per query, there should be a way to override this semantics.
What could be done? I thought it could be done with plugin, but there are nearly zero docs about plugins and looking at code I don't think plugins could solve this because they are not middlewares in the "data transformation pipeline" (I would be happy if there is some place I could inject custom code to transform Go's AST considering some annotations in SQL for example)
What database engines need to be changed?
Postgresql
What programming language backends need to be changed?
select (table_a.*)::table_b from table_a;
select (table_a.id, table_a.name, table_a.size)::table_b from table_a;
But generating go code from them produces a []interface[] result parameter. Seems like the cast could be a hint to use the model type for the other table.
Activity
iamnoah commentedon May 23, 2023
In the same boat. This following are valid SQL:
But generating go code from them produces a
[]interface[]result parameter. Seems like the cast could be a hint to use the model type for the other table.