sqlc
sqlc copied to clipboard
Enums do not work with `ANY` queries
Version
1.25.0
What happened?
I have a table with an enum, and I want to write a query where I can pass a list of possible enum values as a parameter. Codegen works fine, but at runtime the slice of enum values cannot be encoded for the query.
Relevant log output
failed to encode args[2]: unable to encode []dbgen.MyEnum{\"a\", \"b\"} into text format for unknown type (OID 33081): cannot find encode plan
Database schema
CREATE TYPE my_enum AS ENUM ('a', 'b');
CREATE TABLE my_table (
id SERIAL PRIMARY KEY,
enum_field my_enum NOT NULL
);
SQL queries
SELECT * FROM my_table WHERE enum_field = ANY(@param::my_enum[]);
Configuration
version: "2"
sql:
- engine: "postgresql"
schema: "migrations"
queries: "**/queries.sql"
gen:
go:
emit_pointers_for_null_types: true
emit_enum_valid_method: true
out: "generated/dbgen"
sql_package: "pgx/v5"
Playground URL
No response
What operating system are you using?
Linux
What database engines are you using?
PostgreSQL
What type of code are you generating?
Go
Ref https://github.com/sqlc-dev/sqlc/issues/2116#issuecomment-1493299852 for a workaround