-
Notifications
You must be signed in to change notification settings - Fork 930
Open
@khalidibnwalid
Description
What do you want to change?
Problem
When I need to use json_agg of PostgreSQL, it will be casted to an interface{}, so I tried to cast it to a custom struct type
-- -- name: GetRoomsGroupWithRooms :many SELECT sqlc.embed(rooms_groups), COALESCE( json_agg(rooms) FILTER (WHERE rooms.id IS NOT NULL), '[]' )::room[] AS rooms
I then added
overrides: - db_type: "room" go_type: import: "github.com/me/mypkg/models" type: "Rooms"
It did generate the wanted struct
type GetRoomsGroupWithRooms struct { RoomsGroup RoomsGroup `json:"rooms_group"` Rooms []models.Rooms `json:"rooms"` // generated the proper type instead of []interface{} }
But it did also include the ::room[]
part in the generated query, which will cause an error in postgres
Proposed Solution
A macro sqlc.cast() that will do the type casting in the generated go struct, but not in the generated query?
-- -- name: GetRoomsGroupWithRooms :many SELECT sqlc.embed(rooms_groups), COALESCE( json_agg(rooms) FILTER (WHERE rooms.id IS NOT NULL), '[]' )::sqlc.cast(room[]) AS rooms
but the query won't include the ::sqlc.cast(room[])
part at all
What database engines need to be changed?
PostgreSQL
What programming language backends need to be changed?
Go