@@ -498,7 +498,6 @@ func (h *ConnectionHandler) handleQueryOutsideEngine(query ConvertedQuery) (hand
498498 case * sqlparser.Commit :
499499 h .inTransaction = false
500500 case * sqlparser.Deallocate :
501- // TODO: handle ALL keyword
502501 return true , true , h .deallocatePreparedStatement (stmt .Name , h .preparedStatements , query , h .Conn ())
503502 case sqlparser.InjectedStatement :
504503 switch injectedStmt := stmt .Statement .(type ) {
@@ -968,12 +967,21 @@ func startTransactionIfNecessary(ctx *sql.Context) error {
968967 return nil
969968}
970969
970+ // deallocatePreparedStatement handles a DEALLOCATE statement by deleting the corresponding prepared statement from the
971+ // handler's prepared statement map, and sending a CommandComplete message back to the client. Pass an empty |name|
972+ // for `ALL`. This matches the behavior in the parser, which doesn't include a separate field for ALL.
971973func (h * ConnectionHandler ) deallocatePreparedStatement (name string , preparedStatements map [string ]PreparedStatementData , query ConvertedQuery , conn net.Conn ) error {
972- _ , ok := preparedStatements [name ]
973- if ! ok {
974- return errors .Errorf ("prepared statement %s does not exist" , name )
974+ if name == "" {
975+ for name := range preparedStatements {
976+ delete (preparedStatements , name )
977+ }
978+ } else {
979+ _ , ok := preparedStatements [name ]
980+ if ! ok {
981+ return errors .Errorf ("prepared statement %s does not exist" , name )
982+ }
983+ delete (preparedStatements , name )
975984 }
976- delete (preparedStatements , name )
977985
978986 return h .send (& pgproto3.CommandComplete {
979987 CommandTag : []byte (query .StatementTag ),
0 commit comments