Skip to content

Commit 96729e5

Browse files
twmbclaude
authored andcommitted
Address review: move pgtype.NewMap() out of per-row closures
- Create pgtype.NewMap() once in prepareScannersAndGetters, capture in closures instead of allocating per row - Return errors from array scan failures instead of silently falling back to raw strings Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent ffea82a commit 96729e5

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

internal/impl/postgresql/pglogicalstream/snapshotter.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ func prepareScannersAndGetters(columnTypes []*sql.ColumnType) ([]any, []func(any
295295
scanArgs := make([]any, len(columnTypes))
296296
valueGetters := make([]func(any) (any, error), len(columnTypes))
297297

298+
pgTypeMap := pgtype.NewMap()
299+
298300
for i, v := range columnTypes {
299301
switch resolveTypeName(v.DatabaseTypeName()) {
300302
case "VARCHAR", "TEXT", "UUID":
@@ -419,9 +421,8 @@ func prepareScannersAndGetters(columnTypes []*sql.ColumnType) ([]any, []func(any
419421
// pgtype.Int4Array behavior where null elements marshal
420422
// to JSON null).
421423
var result []*int32
422-
m := pgtype.NewMap()
423-
if err := m.SQLScanner(&result).Scan(val.String); err != nil {
424-
return val.String, nil
424+
if err := pgTypeMap.SQLScanner(&result).Scan(val.String); err != nil {
425+
return nil, err
425426
}
426427
return result, nil
427428
}
@@ -436,9 +437,8 @@ func prepareScannersAndGetters(columnTypes []*sql.ColumnType) ([]any, []func(any
436437
// pgtype.TextArray behavior where null elements marshal
437438
// to JSON null).
438439
var result []*string
439-
m := pgtype.NewMap()
440-
if err := m.SQLScanner(&result).Scan(val.String); err != nil {
441-
return val.String, nil
440+
if err := pgTypeMap.SQLScanner(&result).Scan(val.String); err != nil {
441+
return nil, err
442442
}
443443
return result, nil
444444
}

0 commit comments

Comments
 (0)