sqlc icon indicating copy to clipboard operation
sqlc copied to clipboard

`string_agg` has wrong return type

Open angaz opened this issue 4 months ago • 0 comments

Version

1.29.0

What happened?

Using string_agg results in a []byte instead of *string, or pgtype.Text, like I'd expect. The order by in the examples don't make a difference, it's wrong even without it.

Example (from the playground link):

-- name: JustNames :one
SELECT string_agg(name, ', ' ORDER BY name)
FROM authors;

generates:

func (q *Queries) JustNames(ctx context.Context) ([]byte, error) {
	row := q.db.QueryRowContext(ctx, justNames)
	var string_agg []byte
	err := row.Scan(&string_agg)
	return string_agg, err
}

If I inspect the result types in psql:

postgres=> SELECT pg_typeof(string_agg(name, ', ' ORDER BY name)) FROM authors;
 pg_typeof
-----------
 text
(1 row)

Relevant log output


Database schema


SQL queries


Configuration


Playground URL

https://play.sqlc.dev/p/f7b832b8682d08d6482708da863425b3e8a7a6838d5aae26643faf0cf897f4ec

What operating system are you using?

Linux

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

angaz avatar Jun 11 '25 20:06 angaz