From 98c68c21748c41f2349811d85ef633dd00caa5e9 Mon Sep 17 00:00:00 2001 From: mateuszkowalke Date: Thu, 22 Aug 2024 06:51:58 +0200 Subject: [PATCH] Add comment for pgtype.Interval struct Comment explicitly states that pgtype.Interval is a nullable postgres type. --- pgtype/interval.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pgtype/interval.go b/pgtype/interval.go index 4b5116295..228f77e01 100644 --- a/pgtype/interval.go +++ b/pgtype/interval.go @@ -26,6 +26,21 @@ type IntervalValuer interface { IntervalValue() (Interval, error) } +// Interval represents an interval that may be null. +// Interval implements the [Scanner] interface so +// it can be used as a scan destination: +// +// var i Interval +// err := conn.QueryRow(context.Background(), "SELECT elapsed_time FROM foo WHERE id=$1", id).Scan(&i) +// ... +// if i.Valid { +// // use i.Days... +// } else { +// // NULL value +// } +// +// When using as a parameter for prepared statement +// the [Valid] field has to be explicitly set to [true] by the user. type Interval struct { Microseconds int64 Days int32