From 4ebf1d2e0baa87ab6afbbf6a0947c9fb8a30e9d4 Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Sat, 18 Jul 2020 08:44:57 -0500 Subject: [PATCH] Passthrough all parameters directly to pgx --- stdlib/sql.go | 5 +++++ stdlib/sql_test.go | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/stdlib/sql.go b/stdlib/sql.go index a45750ac..a1e966eb 100644 --- a/stdlib/sql.go +++ b/stdlib/sql.go @@ -373,6 +373,11 @@ func (c *Conn) Ping(ctx context.Context) error { return c.conn.Ping(ctx) } +func (c *Conn) CheckNamedValue(*driver.NamedValue) error { + // Underlying pgx supports sql.Scanner and driver.Valuer interfaces natively. So everything can be passed through directly. + return nil +} + type Stmt struct { sd *pgconn.StatementDescription conn *Conn diff --git a/stdlib/sql_test.go b/stdlib/sql_test.go index 87d82943..bceb54a0 100644 --- a/stdlib/sql_test.go +++ b/stdlib/sql_test.go @@ -321,6 +321,15 @@ func TestConnQueryFailure(t *testing.T) { }) } +func TestConnSimpleSlicePassThrough(t *testing.T) { + testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, db *sql.DB) { + var n int64 + err := db.QueryRow("select cardinality($1::text[])", []string{"a", "b", "c"}).Scan(&n) + require.NoError(t, err) + assert.EqualValues(t, 3, n) + }) +} + // Test type that pgx would handle natively in binary, but since it is not a // database/sql native type should be passed through as a string func TestConnQueryRowPgxBinary(t *testing.T) {