Skip to content

Commit

Permalink
clean ps cache after successful deallocate
Browse files Browse the repository at this point in the history
  • Loading branch information
Thiht committed Nov 10, 2023
1 parent 96f5f9c commit 3ec1726
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 3ec1726

Please sign in to comment.