Skip to content

Commit d685c94

Browse files
author
cruvie
committed
fix: ensure driver.Valuer.Value() is called for simple arguments
The convertSimpleArgument function now properly handles driver.Valuer interface by calling the Value() method when the argument implements driver.Valuer. This ensures that custom value types implementing driver.Valuer are correctly processed before being passed to the PostgreSQL type encoding system. This change makes the behavior consistent between simple and extended query protocols regarding driver.Valuer handling.
1 parent fb6c054 commit d685c94

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

values.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package pgx
22

33
import (
4+
"database/sql/driver"
45
"errors"
56
"reflect"
67
"time"
@@ -16,6 +17,15 @@ const (
1617
)
1718

1819
func convertSimpleArgument(m *pgtype.Map, arg any) (any, error) {
20+
// If arg implements driver.Valuer, use Value method
21+
if valuer, ok := arg.(driver.Valuer); ok && valuer != nil {
22+
v, err := valuer.Value()
23+
if err != nil {
24+
return nil, err
25+
}
26+
arg = v
27+
}
28+
1929
fieldValue := reflect.ValueOf(arg)
2030
switch fieldValue.Kind() {
2131
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:

0 commit comments

Comments
 (0)