Skip to content

Return array of composite type from query #2163

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
mxey opened this issue Mar 23, 2023 · 1 comment
Closed

Return array of composite type from query #2163

mxey opened this issue Mar 23, 2023 · 1 comment

Comments

@mxey
Copy link

mxey commented Mar 23, 2023

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

@mxey mxey added enhancement New feature or request triage New issues that hasn't been reviewed labels Mar 23, 2023
@kyleconroy kyleconroy added 📚 postgresql 🔧 golang and removed triage New issues that hasn't been reviewed labels Jun 7, 2023
@kyleconroy
Copy link
Collaborator

Tracking in #2760

@kyleconroy kyleconroy closed this as not planned Won't fix, can't repro, duplicate, stale Sep 26, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants