From 6bf1b0b1b90399c72fc9cc0da9f538341490af7c Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Sat, 22 Feb 2025 08:42:26 -0600 Subject: [PATCH] Add database/sql to overview of scanning --- pgtype/doc.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pgtype/doc.go b/pgtype/doc.go index 50974897..83dfc5de 100644 --- a/pgtype/doc.go +++ b/pgtype/doc.go @@ -164,6 +164,12 @@ plan for scanning into the Go value. A Codec will support scanning into one or m are interfaces rather than explicit types. For example, PointCodec can use any Go type that implements the PointScanner and PointValuer interfaces. +If a Go value is not supported directly by a Codec then Map will try see if it is a sql.Scanner. If is then that +interface will be used to scan the value. Most sql.Scanners require the input to be in the text format (e.g. UUIDs and +numeric). However, pgx will typically have received the value in the binary format. In this case the binary value will be +parsed, reencoded as text, and then passed to the sql.Scanner. This may incur additional overhead for query results with +a large number of affected values. + If a Go value is not supported directly by a Codec then Map will try wrapping it with additional logic and try again. For example, Int8Codec does not support scanning into a renamed type (e.g. type myInt64 int64). But Map will detect that myInt64 is a renamed type and create a plan that converts the value to the underlying int64 type and then passes that to