Skip to content

Return array of composite type from query #2163

Closed as not planned
Closed as not planned
@mxey

Description

@mxey

What do you want to change?

I think this would be a very nice way to return nested data from JOINs.

-- Example queries for sqlc
CREATE TABLE parent (
  id serial primary key,
  name varchar
);

CREATE TABLE child (
  parent_id int,
  col1 varchar,
  col2 varchar
);

-- name: Get :one
SELECT parent.*, array_agg(child)::child[]
FROM parent
JOIN child ON child.parent_id = parent.id;

Unfortunately sqlc generates this type:

type GetRow struct {
	ID      int32
	Name    pgtype.Text
	Column3 []interface{}
}

https://play.sqlc.dev/p/2c28fc8cfbd33e645990e52994a56646791963a08134cbf396f5e12079f443db

pgx seems to have some support for this

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