Skip to content

Cannot retrieve array of custom enums using pgx #1871

Open
@kntajus

Description

@kntajus

Given this SQL:

CREATE TYPE fruit AS ENUM ('apple', 'banana', 'kiwi');

CREATE TABLE choices (
	id int PRIMARY KEY,
	fruits fruit[] NOT NULL
);

-- name: GetChoice :one
SELECT * FROM choices WHERE id = $1;

along with this config:

version: "2"
sql:
- schema: "query.sql"
  queries: "query.sql"
  engine: "postgresql"
  gen:
    go:
      out: "db"
      sql_package: "pgx/v4"

When calling the generated GetChoice function, it panics:

panic: reflect.Value.Convert: value of type *[]db.Fruit cannot be converted to type *[]string

(Example code)

I can't work out if the problem lies with sqlc, pgx, or (more likely) me. Possibly worth noting that if I modify the generated code to make use of pq.Array when scanning into the array, it then works.

Anyone able to advise if I'm doing something wrong?

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