From 0ddf9e3b4b97c566c0c6ce23a622bc49bd03b963 Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Sat, 22 Jan 2022 18:40:46 -0600 Subject: [PATCH] Try wrapping scan target before sql.Scanner This allows wrappers to directly avoid the slow sql.Scanner interface. --- pgtype/pgtype.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/pgtype/pgtype.go b/pgtype/pgtype.go index 150f1a23..cba1bb2f 100644 --- a/pgtype/pgtype.go +++ b/pgtype/pgtype.go @@ -906,14 +906,6 @@ func (ci *ConnInfo) PlanScan(oid uint32, formatCode int16, target interface{}) S if plan := dt.Codec.PlanScan(ci, oid, formatCode, target, false); plan != nil { return plan } - - if _, ok := target.(*interface{}); ok { - return &pointerEmptyInterfaceScanPlan{codec: dt.Codec, ci: ci, oid: oid, formatCode: formatCode} - } - - if _, ok := target.(sql.Scanner); ok { - return &scanPlanCodecSQLScanner{c: dt.Codec, ci: ci, oid: oid, formatCode: formatCode} - } } for _, f := range ci.TryWrapScanPlanFuncs { @@ -927,6 +919,16 @@ func (ci *ConnInfo) PlanScan(oid uint32, formatCode int16, target interface{}) S } } + if dt != nil { + if _, ok := target.(*interface{}); ok { + return &pointerEmptyInterfaceScanPlan{codec: dt.Codec, ci: ci, oid: oid, formatCode: formatCode} + } + + if _, ok := target.(sql.Scanner); ok { + return &scanPlanCodecSQLScanner{c: dt.Codec, ci: ci, oid: oid, formatCode: formatCode} + } + } + if _, ok := target.(sql.Scanner); ok { return &scanPlanSQLScanner{formatCode: formatCode} }