postgreSQL我能够创建一个函数但无法调用它

时间:2019-01-23 07:21:40

标签: postgresql

我正在尝试在postgres中创建一个函数,成功执行了CREATE查询,但是当我尝试调用该函数时,却出现了错误。

 CREATE OR REPLACE FUNCTION sp_generate_random_locations(
 "nwclatitude" NUMERIC,
 "nwclongitude" NUMERIC,
 "seclatitude" NUMERIC,
 "seclongitude" NUMERIC,
 "type" TEXT,
 "count" INTEGER,
 "runid" TEXT
 ) RETURNS INT AS
 $BODY$
 DECLARE
 counter INTEGER := 0 ; 
 id uuid := uuid_generate_v1();
 responder_latitude FLOAT(5):= nwclatitude+(seclatitudenwclatitude)*RANDOM();
 responder_longitude FLOAT(5):= nwclongitude+(seclongitudenwclongitude)*RANDOM();
 BEGIN
 LOOP
 EXIT WHEN counter=count;
--some task
END LOOP;
END;
$BODY$
LANGUAGE plpgsql 
SECURITY DEFINER 
SET search_path = admin, pg_temp;

现在,如果我尝试使用以下命令调用该函数

SELECT aed_modeling.sp_generate_random_locations(“nwclatitude” := 54.42 ,”nwclongitude” := 10.05 ,”seclatitude” := 54.14, “seclongitude” := 10.48,”type” :=’mobile’ ,”count” :=4 ,”runid” := ‘94984cb0-5f69-4326-b492-34fb19c39fc3’);

但是我遇到了以下错误

42883: function sp_generate_random_locations(“nwclatitude” => numeric, ”nwclongitude” => numeric, ”seclatitude” => numeric, “seclongitude” => numeric, ”type” => unknown, ”count” => integer, ”runid” => unknown) does not exist

我不知道我在这里想念的是什么。请注意,使用的“ runid”不是uuid,我将其用作字符串。即使我用::text强制将变量“ type”和“ runid”强制转换,也无法正常工作。

1 个答案:

答案 0 :(得分:2)

最新答复,是的,根据评论,问题在于双引号不正确。复制粘贴问题。 :-D

例如“nwclatitude” := 54.42 should be "nwclatitude" := 54.42