Open
Description
Version
1.29.0
What happened?
When a PostgreSQL enum column is defined as nullable (i.e., without the NOT NULL constraint), sqlc generates interface{} instead of the configured go_type from the overrides section in sqlc.yaml. This occurs even when a go_type override is specified for that enum type.
Expected Behavior:
sqlc should respect the go_type
override in sqlc.yaml
even when the database column is nullable. In this example, sqlc should generate the EnumCol
field with type string.
Current Behavior:
sqlc generates the EnumCol
field with type interface{}
when the database column is nullable.
Relevant log output
Database schema
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
DO $$
BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'my_enum') THEN
CREATE TYPE my_enum AS ENUM ('value1', 'value2');
END IF;
END
$$;
CREATE TABLE my_table (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
enum_col my_enum DEFAULT 'value1' -- Note: No NOT NULL constraint
);
SQL queries
Configuration
version: "2"
sql:
- engine: "postgresql"
queries: "./db/query/"
schema: "./db/migration/"
gen:
go:
package: "db"
out: "./db/sqlc"
emit_json_tags: true
overrides:
- db_type: "my_enum"
go_type: "string"
Playground URL
What operating system are you using?
Windows
What database engines are you using?
PostgreSQL
What type of code are you generating?
Go