Jos*_*rek 25 mysql postgresql plpgsql
我可以成功创建一个函数如下:
CREATE FUNCTION Foo(MY_Value INT) RETURNS INT
AS 'SELECT 2 + MY_Value'
LANGUAGE SQL
Run Code Online (Sandbox Code Playgroud)
但是,如果我首先要检查函数是否存在然后删除它,那么我必须指定以下内容:
DROP FUNCTION IF EXISTS Foo(My_Value INT);
Run Code Online (Sandbox Code Playgroud)
在不指定输入参数的情况下,以下内容返回错误,指出"NOTICE:function foo()不存在,跳过"
DROP FUNCTION IF EXISTS Foo();
Run Code Online (Sandbox Code Playgroud)
与MySQL类似,有没有办法在PostgreSQL中删除FUNCTION而无需为函数指定参数?换句话说,在MySQL语句中是否存在以下等价物(即,在不指定输入参数的情况下删除存储过程)?
DROP PROCEDURE IF EXISTS Foo;
Run Code Online (Sandbox Code Playgroud)
kli*_*lin 56
在Postgres中,函数可以重载,因此必须使用参数来区分重载函数.要明确地识别函数,您只能放置其参数类型.
DROP FUNCTION IF EXISTS Foo(INT);
Run Code Online (Sandbox Code Playgroud)
从Postgres 10开始,只要名称对于其模式是唯一的,您就可以按名称删除函数.
例:
drop function if exists Foo;
Run Code Online (Sandbox Code Playgroud)
文档在这里.