Skip to content

DEALLOCATE

Remove prepared statements that were created during the current session.

DEALLOCATE { name | ALL }

You can remove a specific prepared statement by name (without arguments), or you can remove all prepared statements.

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

Parent topic:SQL Commands