From 59fa1868a788a860aeec78ace1ee2ade4ee30810 Mon Sep 17 00:00:00 2001 From: Michael Darr Date: Tue, 13 Jul 2021 00:24:58 -0400 Subject: [PATCH] Support time durations for simple protocol Signed-off-by: Michael Darr --- conn_test.go | 13 +++++++++++++ values.go | 2 ++ 2 files changed, 15 insertions(+) diff --git a/conn_test.go b/conn_test.go index 2f37044c..beddcdcd 100644 --- a/conn_test.go +++ b/conn_test.go @@ -1061,3 +1061,16 @@ func TestStmtCacheInvalidationTx(t *testing.T) { ensureConnValid(t, conn) } + +func TestInsertDurationInterval(t *testing.T) { + testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, conn *pgx.Conn) { + _, err := conn.Exec(context.Background(), "create temporary table t(duration INTERVAL(0) NOT NULL)") + require.NoError(t, err) + + result, err := conn.Exec(context.Background(), "insert into t(duration) values($1)", time.Minute) + require.NoError(t, err) + + n := result.RowsAffected() + require.EqualValues(t, 1, n) + }) +} diff --git a/values.go b/values.go index 45d8ff83..1a945475 100644 --- a/values.go +++ b/values.go @@ -78,6 +78,8 @@ func convertSimpleArgument(ci *pgtype.ConnInfo, arg interface{}) (interface{}, e return arg, nil case bool: return arg, nil + case time.Duration: + return fmt.Sprintf("%d microsecond", int64(arg)/1000), nil case time.Time: return arg, nil case string: