From 89f69aaea9748ae0ea121af4f1886d24966cef56 Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Sat, 1 Oct 2022 10:41:40 -0500 Subject: [PATCH] Date text encoding includes leading zero for month and day e.g. 2000-01-01 instead of 2000-1-1. PostgreSQL accepted it without zeroes but our text decoder didn't. This caused a problem when we needed to take a value and encode to text so something else could parse it as if it had come from the PostgreSQL server in text format. e.g. database/sql compatibility. --- pgtype/date.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pgtype/date.go b/pgtype/date.go index 78c5db92..24ed20cc 100644 --- a/pgtype/date.go +++ b/pgtype/date.go @@ -195,8 +195,14 @@ func (encodePlanDateCodecText) Encode(value any, buf []byte) (newBuf []byte, err buf = strconv.AppendInt(buf, int64(year), 10) buf = append(buf, '-') + if date.Time.Month() < 10 { + buf = append(buf, '0') + } buf = strconv.AppendInt(buf, int64(date.Time.Month()), 10) buf = append(buf, '-') + if date.Time.Day() < 10 { + buf = append(buf, '0') + } buf = strconv.AppendInt(buf, int64(date.Time.Day()), 10) if bc {