From 3ec1726dbeb3743fe967ee7afd97e5b30719069b Mon Sep 17 00:00:00 2001 From: Thibaut Rousseau Date: Fri, 10 Nov 2023 14:56:13 +0100 Subject: [PATCH] clean ps cache after successful deallocate --- conn.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/conn.go b/conn.go index 0426873c2..522424748 100644 --- a/conn.go +++ b/conn.go @@ -340,15 +340,18 @@ func (c *Conn) Prepare(ctx context.Context, name, sql string) (sd *pgconn.Statem // Deallocate releases a prepared statement. func (c *Conn) Deallocate(ctx context.Context, name string) error { - var psName string + psName := name if sd, ok := c.preparedStatements[name]; ok { - delete(c.preparedStatements, name) psName = sd.Name - } else { - psName = name } + _, err := c.pgConn.Exec(ctx, "deallocate "+quoteIdentifier(psName)).ReadAll() - return err + if err != nil { + return err + } + + delete(c.preparedStatements, name) + return nil } // DeallocateAll releases all previously prepared statements from the server and client, where it also resets the statement and description cache.