Skip to content

DEALLOCATE

Remove prepared statements that were created during the current session.

DEALLOCATE [ IF EXISTS ] { name | ALL }

You can remove a specific prepared statement by name (without arguments), or you can remove all prepared statements. If you use the IF EXISTS option, no error message is returned if the named statement does not exist.

For example:

premdb=# prepare x(varchar(30)) as select * from team where name=$1;
PREPARE
premdb=# execute x('Leicester City');
 teamid | htid | atid |      name      | nickname |   city    |      stadium       | capacity | avg_att 
--------+------+------+----------------+----------+-----------+--------------------+----------+---------
    22 |   23 |   72 | Leicester City | Foxes    | Leicester | King Power Stadium |    32262 |  32.201
(1 row)
premdb=# deallocate all;
DEALLOCATE ALL
premdb=# execute x('Leicester City');
ERROR:  prepared statement "x" does not exist

Note that the DEALLOCATE syntax does not require you to provide the arguments to the prepared statement, just its name:

premdb=# prepare avgsales(int) as select ...
PREPARE
...
premdb=# deallocate avgsales;
DEALLOCATE