From 29109487ec1cc26d44fe3eaac375c118a15abbf2 Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Sat, 12 Nov 2022 06:21:48 -0600 Subject: [PATCH] DateCodec.DecodeDatabaseSQLValue returns time.Time when possible Previously it returned a string. However, this was an unintended behavior change from pgx v4. https://github.com/jackc/pgx/commit/89f69aaea9748ae0ea121af4f1886d24966cef56#commitcomment-89173737 --- pgtype/date.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/pgtype/date.go b/pgtype/date.go index bb65996a..0c817c94 100644 --- a/pgtype/date.go +++ b/pgtype/date.go @@ -308,7 +308,21 @@ func (scanPlanTextAnyToDateScanner) Scan(src []byte, dst any) error { } func (c DateCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error) { - return codecDecodeToTextFormat(c, m, oid, format, src) + if src == nil { + return nil, nil + } + + var date Date + err := codecScan(c, m, oid, format, src, &date) + if err != nil { + return nil, err + } + + if date.InfinityModifier != Finite { + return date.InfinityModifier.String(), nil + } + + return date.Time, nil } func (c DateCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (any, error) {