diff --git a/pgtype/array.go b/pgtype/array.go index 93f5aa9b..0fa4c129 100644 --- a/pgtype/array.go +++ b/pgtype/array.go @@ -463,7 +463,7 @@ func (a FlatArray[T]) IndexType() any { func (a *FlatArray[T]) SetDimensions(dimensions []ArrayDimension) error { if dimensions == nil { - a = nil + *a = nil return nil } diff --git a/query_test.go b/query_test.go index 78cacb6c..7fa507b0 100644 --- a/query_test.go +++ b/query_test.go @@ -1094,6 +1094,21 @@ func TestReadingNullByteArrays(t *testing.T) { } } +func TestQueryNullSliceIsSet(t *testing.T) { + conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE")) + defer closeConn(t, conn) + + a := []int32{1, 2, 3} + err := conn.QueryRow(context.Background(), "select null::int[]").Scan(&a) + if err != nil { + t.Fatalf("conn.QueryRow failed: %v", err) + } + + if a != nil { + t.Errorf("Expected 'a' to be nil, but it was: %v", a) + } +} + func TestConnQueryDatabaseSQLScanner(t *testing.T) { t.Parallel()