更新时间:2024-08-20 GMT+08:00

DEALLOCATE

功能描述

DEALLOCATE用于删除预备语句。

注意事项

  • 如果用户没有明确删除一个预备语句,那么它将在会话结束的时候被删除。
  • 语法中PREPARE关键字总会被忽略。

语法格式

1
DEALLOCATE [ PREPARE ] { name | ALL };

参数说明

  • name

    将要删除的预备语句。

  • ALL

    删除所有预备语句。

示例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
--查看现有预备语句。
gaussdb=# SELECT name, statement, parameter_types FROM pg_prepared_statements;
 name | statement | parameter_types 
------+-----------+-----------------
(0 rows)

--创建q1,q2,q3,q4四个预备语句。
gaussdb=# PREPARE q1 AS SELECT 1 AS a;
PREPARE
gaussdb=# PREPARE q2 AS SELECT 1 AS a;
PREPARE
gaussdb=# PREPARE q3 AS SELECT 1 AS a;
PREPARE
gaussdb=# PREPARE q4 AS SELECT 1 AS a;
PREPARE

--再次查看现有预备语句。
gaussdb=# SELECT name, statement, parameter_types FROM pg_prepared_statements;
 name |          statement           | parameter_types 
------+------------------------------+-----------------
 q1   | PREPARE q1 AS SELECT 1 AS a; | {}
 q4   | PREPARE q4 AS SELECT 1 AS a; | {}
 q3   | PREPARE q3 AS SELECT 1 AS a; | {}
 q2   | PREPARE q2 AS SELECT 1 AS a; | {}
(4 rows)

--删除q4预备语句并查看剩余预备语句。
gaussdb=# DEALLOCATE q4;
gaussdb=# SELECT name, statement, parameter_types FROM pg_prepared_statements;
 name |          statement           | parameter_types 
------+------------------------------+-----------------
 q1   | PREPARE q1 AS SELECT 1 AS a; | {}
 q3   | PREPARE q3 AS SELECT 1 AS a; | {}
 q2   | PREPARE q2 AS SELECT 1 AS a; | {}
(3 rows

--删除所有预备语句并查看剩余预备语句。
gaussdb=# DEALLOCATE ALL;
DEALLOCATE ALL
gaussdb=# SELECT name, statement, parameter_types FROM pg_prepared_statements;
 name | statement | parameter_types 
------+-----------+-----------------
(0 rows)