From c94c47f584cf7d52d31b143083870868898527bf Mon Sep 17 00:00:00 2001 From: Bodo Kaiser Date: Thu, 10 Nov 2022 13:46:53 +0100 Subject: [PATCH] added DeallocateAll to pgx.Conn to clear prepared statement cache --- conn.go | 7 +++++++ conn_test.go | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/conn.go b/conn.go index 2ab009ff..7dee1eec 100644 --- a/conn.go +++ b/conn.go @@ -326,6 +326,13 @@ func (c *Conn) Deallocate(ctx context.Context, name string) error { return err } +// Deallocate all released prepared statements +func (c *Conn) DeallocateAll(ctx context.Context, name string) error { + c.preparedStatements = map[string]*pgconn.StatementDescription{} + _, err := c.pgConn.Exec(ctx, "deallocate all").ReadAll() + return err +} + func (c *Conn) bufferNotifications(_ *pgconn.PgConn, n *pgconn.Notification) { c.notifications = append(c.notifications, n) } diff --git a/conn_test.go b/conn_test.go index 9cf5fd58..0fafeb18 100644 --- a/conn_test.go +++ b/conn_test.go @@ -424,7 +424,7 @@ func TestPrepare(t *testing.T) { t.Errorf("Prepared statement did not return expected value: %v", s) } - err = conn.Deallocate(context.Background(), "test") + err = conn.DeallocateAll(context.Background(), "test") if err != nil { t.Errorf("conn.Deallocate failed: %v", err) }