PostgreSQL:如何在没有指定参数的情况下删除功能?

时间:2022-11-15 22:58:27

I can successfully create a function as follows:

我可以成功创建一个函数如下:

CREATE FUNCTION Foo(MY_Value INT) RETURNS INT
AS 'SELECT 2 + MY_Value'
LANGUAGE SQL

However, if I first want to check if the function exists and then drop it if I does, I must specify the following:

但是,如果我首先要检查函数是否存在然后删除它,那么我必须指定以下内容:

DROP FUNCTION IF EXISTS Foo(My_Value INT);

Without specifying the input parameters, the following returns an error stating "NOTICE: function foo() does not exist, skipping"

在不指定输入参数的情况下,以下内容返回错误,指出“注意:函数foo()不存在,跳过”

DROP FUNCTION IF EXISTS Foo();

Similar to MySQL, is there a way to drop a FUNCTION in PostgreSQL without having to specify the parameters to the function? In other words, is there an equivalent for the following in MySQL statement (i.e., drop the stored procedure without specifying the input parameters)?

与MySQL类似,有没有办法在PostgreSQL中删除FUNCTION而不必为函数指定参数?换句话说,在MySQL语句中是否存在以下等价物(即,在不指定输入参数的情况下删除存储过程)?

DROP PROCEDURE IF EXISTS Foo;

2 个解决方案

#1


42  

In Postgres functions can be overloaded, so parameters are necessary to distinguish overloaded functions. To unambiguously identify a function you can put only types of its parameters.

在Postgres中,函数可以重载,因此必须使用参数来区分重载函数。要明确地识别函数,您只能放置其参数类型。

DROP FUNCTION IF EXISTS Foo(INT);

#2


3  

As of Postgres 10 you can drop functions by name only, as long as the names are unique to their schema.

从Postgres 10开始,只要名称对于其模式是唯一的,您就可以按名称删除函数。

Example:

例:

drop function if exists Foo;

Documentation here.

文档在这里。

#1


42  

In Postgres functions can be overloaded, so parameters are necessary to distinguish overloaded functions. To unambiguously identify a function you can put only types of its parameters.

在Postgres中,函数可以重载,因此必须使用参数来区分重载函数。要明确地识别函数,您只能放置其参数类型。

DROP FUNCTION IF EXISTS Foo(INT);

#2


3  

As of Postgres 10 you can drop functions by name only, as long as the names are unique to their schema.

从Postgres 10开始,只要名称对于其模式是唯一的,您就可以按名称删除函数。

Example:

例:

drop function if exists Foo;

Documentation here.

文档在这里。