From 07391e1d5e1dc67386e1a9ed4f8db45b3593e027 Mon Sep 17 00:00:00 2001 From: Boban Acimovic Date: Fri, 2 Dec 2022 08:34:44 +0100 Subject: [PATCH] add empty --- pgtype/range.go | 4 ++++ pgtype/range_test.go | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/pgtype/range.go b/pgtype/range.go index 8eb2281de..56675002f 100644 --- a/pgtype/range.go +++ b/pgtype/range.go @@ -385,6 +385,10 @@ func (dst *Range[T]) UnmarshalJSON(b []byte) error { Valid: true, } + if dst.LowerType == Empty && dst.UpperType == Empty { + return nil + } + if err = json.Unmarshal([]byte(`"`+r.Lower+`"`), &dst.Lower); err != nil { return err } diff --git a/pgtype/range_test.go b/pgtype/range_test.go index 702c0dd7f..7b8ce5a27 100644 --- a/pgtype/range_test.go +++ b/pgtype/range_test.go @@ -249,6 +249,11 @@ func TestRangeDateUnmarshalJSON(t *testing.T) { result Range[Date] }{ {src: "null", result: Range[Date]{}}, + {src: `"empty"`, result: Range[Date]{ + LowerType: Empty, + UpperType: Empty, + Valid: true, + }}, {src: `"(2022-12-01,2022-12-31)"`, result: Range[Date]{ Lower: Date{Time: time.Date(2022, 12, 1, 0, 0, 0, 0, time.UTC), Valid: true}, Upper: Date{Time: time.Date(2022, 12, 31, 0, 0, 0, 0, time.UTC), Valid: true},