#1871·sqlc

Cannot retrieve array of custom enums using pgx

Author: kntajusCreated Oct 1, 2022Updated Aug 31, 2026
Labelsinvalid:books: postgresql:wrench: golangpgx/v4

Given this SQL:

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:

yaml
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?