Skip to content

Support RECORD columns in PostgreSQL #349

Closed
@brianhv

Description

@brianhv

Example schema and query (fiddle):

CREATE TABLE location (
  id bigint primary key,
  name text
);

CREATE TABLE book (
  id bigint primary key,
  location_id bigint references location(id),
  name text
);

INSERT INTO location (id, name) VALUES (1, 'The nearby one');
INSERT INTO location (id, name) VALUES (2, 'The one across town');

INSERT INTO book (id, location_id, name) VALUES (1, 1, 'The Hitchhiker''s Guide to the Galaxy');
INSERT INTO book (id, location_id, name) VALUES (2, 1, 'The Restaurant at the End of the Universe');
INSERT INTO book (id, location_id, name) VALUES (3, 2, 'Life, the Universe and Everything');
INSERT INTO book (id, location_id, name) VALUES (4, 2, 'So Long, and Thanks for All the Fish');
INSERT INTO book (id, location_id, name) VALUES (5, 2, 'Mostly Harmless');

SELECT location.id, location.name, books_at_location.bal
FROM location
LEFT JOIN LATERAL (
    SELECT ARRAY_AGG(ROW(book.id, book.name)) bal
    FROM book
    WHERE location.id = book.location_id
) books_at_location ON true;
id name bal
1 The nearby one {"(1,"The Hitchhiker's Guide to the Galaxy")","(2,"The Restaurant at the End of the Universe")"}
2 The one across town {"(3,"Life, the Universe and Everything")","(4,"So Long, and Thanks for All the Fish")","(5,"Mostly Harmless")"}

Currently sqlx gives the error message
error: unsupported type RECORD[] of column #3 ("bal")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions