Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions internal/compiler/output_columns.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,24 @@ func (c *Compiler) outputColumns(qc *QueryCatalog, node ast.Node) ([]*Column, er
first.Name = *res.Name
}
cols = append(cols, first)
case ast.ARRAY_SUBLINK:
arrName := "array"
if res.Name != nil {
arrName = *res.Name
}
subcols, err := c.outputColumns(qc, n.Subselect)
if err != nil {
return nil, err
}
if len(subcols) != 1 {
cols = append(cols, &Column{Name: arrName, DataType: "any"})
break
}
col := *subcols[0] // copy, don't mutate the subquery's column.
col.Name = arrName
col.IsArray = true
col.ArrayDims++
cols = append(cols, &col)
default:
cols = append(cols, &Column{Name: name, DataType: "any", NotNull: false})
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-- name: ListSingerAlbums :many
SELECT
id,
ARRAY(
SELECT album_id
FROM albums
WHERE albums.singer_id = singers.id
)
FROM singers;

-- name: ListSingerAlbumsWithAlias :many
SELECT
id,
ARRAY(
SELECT album_id
FROM albums
WHERE albums.singer_id = singers.id
) AS titles
FROM singers;
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CREATE TABLE singers (
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
name TEXT NOT NULL
);

CREATE TABLE albums(
singer_id BIGINT NOT NULL REFERENCES singers (id),
album_id BIGINT NOT NULL,
PRIMARY KEY (singer_id, album_id)
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": "1",
"packages": [
{
"path": "go",
"engine": "postgresql",
"sql_package": "pgx/v5",
"name": "querytest",
"schema": "schema.sql",
"queries": "query.sql"
}
]
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-- name: ListSingerAlbums :many
SELECT
id,
ARRAY(
SELECT album_id
FROM albums
WHERE albums.singer_id = singers.id
)
FROM singers;

-- name: ListSingerAlbumsWithAlias :many
SELECT
id,
ARRAY(
SELECT album_id
FROM albums
WHERE albums.singer_id = singers.id
) AS titles
FROM singers;
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CREATE TABLE singers (
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
name TEXT NOT NULL
);

CREATE TABLE albums(
singer_id BIGINT NOT NULL REFERENCES singers (id),
album_id BIGINT NOT NULL,
PRIMARY KEY (singer_id, album_id)
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"version": "1",
"packages": [
{
"path": "go",
"name": "querytest",
"schema": "schema.sql",
"queries": "query.sql"
}
]
}
2 changes: 2 additions & 0 deletions internal/sql/ast/sub_link.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ func (n *SubLink) Format(buf *TrackedBuffer, d format.Dialect) {
switch n.SubLinkType {
case EXISTS_SUBLINK:
buf.WriteString("EXISTS (")
case ARRAY_SUBLINK:
buf.WriteString("ARRAY (")
case ANY_SUBLINK:
if hasTestExpr {
buf.WriteString(" IN (")
Expand Down
Loading