Postgresql 中文操作指南
Synopsis
DROP PROCEDURE [ IF EXISTS ] name [ ( [ [ argmode ] [ argname ] argtype [, ...] ] ) ] [, ...]
[ CASCADE | RESTRICT ]
Description
DROP PROCEDURE 删除一个或多个现有过程的定义。要执行此命令,用户必须是该过程的所有者。通常必须指定过程中参数类型,因为可能存在具有相同名称和不同参数列表的多个不同过程。
DROP PROCEDURE removes the definition of one or more existing procedures. To execute this command the user must be the owner of the procedure(s). The argument types to the procedure(s) usually must be specified, since several different procedures can exist with the same name and different argument lists.
Parameters
-
IF EXISTS
-
Do not throw an error if the procedure does not exist. A notice is issued in this case.
-
-
name
-
The name (optionally schema-qualified) of an existing procedure.
-
-
argmode
-
The mode of an argument: IN, OUT, INOUT, or VARIADIC. If omitted, the default is IN (but see below).
-
-
argname
-
The name of an argument. Note that DROP PROCEDURE does not actually pay any attention to argument names, since only the argument data types are used to determine the procedure’s identity.
-
-
argtype
-
The data type(s) of the procedure’s arguments (optionally schema-qualified), if any. See below for details.
-
-
CASCADE
-
Automatically drop objects that depend on the procedure, and in turn all objects that depend on those objects (see Section 5.14).
-
-
RESTRICT
-
Refuse to drop the procedure if any objects depend on it. This is the default.
-
Notes
如果只存在一个指定名称的过程,则可以省略参数列表。此时,也省略掉括号。
If there is only one procedure of the given name, the argument list can be omitted. Omit the parentheses too in this case.
在 PostgreSQL 中,列出输入(包括 INOUT )参数就足够了,因为两个同名例程不允许共享同一个输入参数列表。此外, DROP 命令实际上不会检查是否正确地编写了 OUT 参数的类型;因此,被明确标记为 OUT 的任何参数都是噪音。不过,为了与相应的 CREATE 命令保持一致,建议编写这些参数。
In PostgreSQL, it’s sufficient to list the input (including INOUT) arguments, because no two routines of the same name are allowed to share the same input-argument list. Moreover, the DROP command will not actually check that you wrote the types of OUT arguments correctly; so any arguments that are explicitly marked OUT are just noise. But writing them is recommendable for consistency with the corresponding CREATE command.
为了与 SQL 标准兼容,还允许编写所有参数数据类型(包括 OUT 参数的数据类型),而没有任何 argmode 标记。完成之时的过程 OUT 参数 will 类型将被针对该命令进行验证。此规定会产生歧义,因为当参数列表不包含任何 argmode 标记时,则不清楚打算使用哪条规则。 DROP 命令将尝试通过两种方式进行查找,如果找到两个不同的过程,它会抛出一个错误。为了避免出现此类歧义的风险,建议明确编写 IN 标记而不是让它们默认化,从而强制使用传统的 PostgreSQL 解释。
For compatibility with the SQL standard, it is also allowed to write all the argument data types (including those of OUT arguments) without any argmode markers. When this is done, the types of the procedure’s OUT argument(s) will be verified against the command. This provision creates an ambiguity, in that when the argument list contains no argmode markers, it’s unclear which rule is intended. The DROP command will attempt the lookup both ways, and will throw an error if two different procedures are found. To avoid the risk of such ambiguity, it’s recommendable to write IN markers explicitly rather than letting them be defaulted, thus forcing the traditional PostgreSQL interpretation to be used.
刚解释过的查找规则也被会对现有的过程发起操作的其他命令使用,例如 ALTER PROCEDURE 和 COMMENT ON PROCEDURE 。
The lookup rules just explained are also used by other commands that act on existing procedures, such as ALTER PROCEDURE and COMMENT ON PROCEDURE.
Examples
如果只存在一个过程 do_db_maintenance ,则此命令就足够删除它:
If there is only one procedure do_db_maintenance, this command is sufficient to drop it:
DROP PROCEDURE do_db_maintenance;
给定该过程定义:
Given this procedure definition:
CREATE PROCEDURE do_db_maintenance(IN target_schema text, OUT results text) ...
可以使用以下任何一个命令来删除此过程:
any one of these commands would work to drop it:
DROP PROCEDURE do_db_maintenance(IN target_schema text, OUT results text);
DROP PROCEDURE do_db_maintenance(IN text, OUT text);
DROP PROCEDURE do_db_maintenance(IN text);
DROP PROCEDURE do_db_maintenance(text);
DROP PROCEDURE do_db_maintenance(text, text); -- potentially ambiguous
但是,如果还存在以下命令,则最后一个示例就将变得模棱两可:
However, the last example would be ambiguous if there is also, say,
CREATE PROCEDURE do_db_maintenance(IN target_schema text, IN options text) ...