Skip to content

UNION ALL queries generate unexpected row types instead of using the base table type #3832

Open
@mgrisole

Description

@mgrisole

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions