postgreSQL 中不存在该函数..为什么?

Mak*_*kov 4 postgresql

请需要您的帮助,不明白为什么我收到以下错误,我不是专业的 postgresql 开发人员..

正如您可以看到创建的函数,那么为什么会发生函数不存在呢?

create or replace function loginAttempt (u_email character varying, u_password character varying, date_time timestamptz, OUT attempt smallint) returns smallint AS $$
   BEGIN
        INSERT INTO login_attempts (typed_password, date_time, attempt_nu, email) VALUES (u_password, date_time, attempt_nu, email);
        IF attempt = 3 THEN INSERT INTO warnings (u_email,u_password) VALUES (u_email,u_password);
        END IF;
   END;
$$ LANGUAGE plpgsql;


  select loginattempt ('Jon.Jones88@gmail.com','+_@kjhfdb987', now(), 1);
Run Code Online (Sandbox Code Playgroud)

错误:函数loginattempt(未知,未知,带时区的时间戳,整数)不存在第1行:选择loginattempt('Jon.Jones88@gmail.com','+_@kjhfdb987',... ^提示:无函数匹配给定的名称和参数类型。您可能需要添加显式类型转换。SQL 状态:42883 字符:8

在此输入图像描述

小智 5

您已将最后一个参数定义为 OUT 参数,这意味着您无法为其传递值。

您需要使用:

select loginattempt ('Jon.Jones88@gmail.com','+_@kjhfdb987', now());
Run Code Online (Sandbox Code Playgroud)

由于您没有写入参数,所以attempts我看不出有什么理由将其定义为输出参数。如果需要,您可以简单地返回该值:

create or replace function loginAttempt (u_email character varying, u_password character varying, u_date_time timestamptz, u_attempt smallint) 
  returns smallint 
AS $$
BEGIN
  INSERT INTO login_attempts (typed_password, date_time, attempt_nu, email) 
  VALUES (u_password, u_date_time, u_attempt, u_email);
  IF u_attempt = 3 THEN 
    INSERT INTO warnings (u_email,u_password) VALUES (u_email,u_password);
  END IF;
  return u_attempt;
END;
$$ LANGUAGE plpgsql;
Run Code Online (Sandbox Code Playgroud)

由于该值1被假定为整数,因此在调用函数时需要转换该值:

select loginattempt ('Jon.Jones88@gmail.com','+_@kjhfdb987', now(), 1::smallint);
Run Code Online (Sandbox Code Playgroud)

在线示例: https: //rextester.com/YNIQ55561