Skip to content

string_agg has wrong return type #3987

Open
@angaz

Description

@angaz

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

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