首页 > 解决方案 > 我能够创建一个函数但无法调用它

问题描述

我正在尝试在 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,我将其用作字符串。即使我输入变量“type”和“runid”::text也不起作用。

标签: postgresql

解决方案


迟到的回应,是的,根据评论,问题在于不正确的双引号。复制粘贴问题。:-D

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


推荐阅读