Open
Description
Description
When using UNION ALL
in a query, SQLC generates a new row type (e.g., FindOrCreateAssetsByNameAndSymbolRow
) instead of using the base table type (Asset
), even though both parts of the UNION are returning the same table structure.
Current Behavior
Given a query like this:
-- name: FindOrCreateAssetsByNameAndSymbol :many
WITH new_assets AS (
INSERT INTO asset (name, symbol)
SELECT unnest(@names::text[]), unnest(@symbols::text[])
WHERE NOT EXISTS (...)
RETURNING *
)
SELECT * FROM new_assets
UNION ALL
SELECT * FROM asset
WHERE ...;
SQLC generates:
func (q *Queries) FindOrCreateAssetsByNameAndSymbol(ctx context.Context, arg FindOrCreateAssetsByNameAndSymbolParams) ([]FindOrCreateAssetsByNameAndSymbolRow, error)
Expected Behavior
Since both parts of the UNION ALL return the same table structure (asset), the generated function should return the base table type:
func (q *Queries) FindOrCreateAssetsByNameAndSymbol(ctx context.Context, arg FindOrCreateAssetsByNameAndSymbolParams) ([]Asset, error)
What database engines need to be changed?
PostgreSQL
What programming language backends need to be changed?
Go