From 838103da395fbb5b1b7d5304412d82f93d0695d7 Mon Sep 17 00:00:00 2001 From: daxx06 <181129978+daxx06@users.noreply.github.com> Date: Wed, 2 Sep 2026 13:25:42 +0530 Subject: [PATCH] fix(codegen/golang): map nullable PostgreSQL UUID[] columns to pointer slices (*[]uuid.UUID) for scan safety --- internal/codegen/golang/struct.go | 36 ++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/internal/codegen/golang/struct.go b/internal/codegen/golang/struct.go index de637cd..593afc6 100644 --- a/internal/codegen/golang/struct.go +++ b/internal/codegen/golang/struct.go @@ -4,19 +4,35 @@ import ( "github.com/sqlc-dev/sqlc/internal/plugin" ) -func (g *Generator) goType(col *plugin.Column) string { - // Existing logic... - // Add logic to check if column is nullable and is an array type - if col.NotNull == false && isArrayType(col.Type) { - return "*[]" + baseType(col.Type) +// GoType returns the Go type for a database column, handling nullable array types correctly. +func (g *Generator) GoType(col *plugin.Column, settings Settings) string { + typ := g.dbType(col, settings) + + if col.IsArray { + if !col.NotNull { + // Nullable array columns map to *[]Type for standard lib/pq scanning + return "*[]" + typ + } + return "[]" + typ + } + + if !col.NotNull { + if settings.GoTypePointer { + return "*" + typ + } + return g.nullableType(typ, settings) } - return g.defaultGoType(col) + + return typ } -func isArrayType(t string) bool { - return t == "uuid[]" // Simplified for demonstration +func (g *Generator) dbType(col *plugin.Column, settings Settings) string { + if col.Type.Name == "uuid" { + return "uuid.UUID" + } + return col.Type.Name } -func baseType(t string) string { - return "uuid.UUID" +func (g *Generator) nullableType(typ string, settings Settings) string { + return "*" + typ } \ No newline at end of file