From 04fd6873248c969ca0e7531a390daaa5a2252790 Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Tue, 7 Dec 2021 21:00:22 +0000 Subject: [PATCH] Handle null values in numeric --- postgres/numeric.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/postgres/numeric.go b/postgres/numeric.go index 82c09a8..21e24cc 100644 --- a/postgres/numeric.go +++ b/postgres/numeric.go @@ -7,6 +7,9 @@ type Numeric struct { } func (n Numeric) GetFloat64() float64 { + if n.Status != pgtype.Present { + return 0 + } var balance float64 err := n.AssignTo(&balance) if err != nil { @@ -16,11 +19,17 @@ func (n Numeric) GetFloat64() float64 { } func (n Numeric) GetPositive() bool { + if n.Status != pgtype.Present { + return true + } float := n.GetFloat64() return float >= 0 } func (n Numeric) IsZero() bool { + if n.Status != pgtype.Present { + return true + } float := n.GetFloat64() return float == 0 }