我试图从Django/Python调用Postgres/PLPGSQL上的存储过程。我使用可变参数定义了存储过程:
CREATE OR REPLACE FUNCTION udf_getmultiplecategoriescodetypes (VARIADIC NUMERIC[])
那么我只想在proc中使用参数数组的地方是WHERE stmt:
^{pr2}$当我从DBeaver控制台调用函数时,所有这些工作都非常完美:
SELECT * FROM udf_getmultiplecategoriescodetypes(1, 2)
但是,如果我在Django/Python中使用callproc函数,使用相同类型的语法,如下所示:
c.callproc("udf_getmultpilecategoriescodetypes", (1, 2))
我有错误:
LINE 1: SELECT * FROM udf_getmultpilecategoriescodetypes(1,2)
HINT: No function matches the given name and argument types. You might need to add
explicit type casts.
function udf_getmultpilecategoriescodetypes(integer, integer) does not exist
如果在函数中找不到它,那么当函数在dber中被创建时,我会说它不能被保存在函数中。在
我发现我可以使用DROP函数删除它,并包含可变参数,这样它就可以根据参数的数量和类型来识别它。但为什么会这样?在
所以,有两个问题:
您将参数定义为
VARIADIC NUMERIC[]
,因此您确实希望传递一个numeric
数组,而不是integer上的数组。在因为它是一个
VARIADIC
函数,所以可以传递一个numeric
值的列表,而不是像您一样传递一个实际的数组。参见:但这不是眼下的问题。如果没有
func(int[])
,Postgresfunction type resolution将返回到func(numeric[])
。似乎是一个简单的打字错误。你看到区别了吗?在简明扼要的名字和一些下划线可能有助于防止此类打字错误。在
Postgres允许函数重载。因此,函数签名由其名称和参数组成,以确保不含糊。DBeaver与此无关。在
最重要的是,要知道同一个函数可以存在于多个模式中。因此,请确保使用正确的
search_path
操作,并且不要在另一个模式中拥有(并且无意中调用)副本。在因此,由于缺少参数,您尝试删除函数
public.udf_getmultiplecategoriescodetypes()
失败。如果函数是在不同的模式下创建的,它也可能失败。在相关:
相关问题 更多 >
编程相关推荐