繁体   English   中英

使用PostgreSQL在pgAdmin中调用函数时函数不存在错误消息

[英]Function does not exist error message while calling a function in pgAdmin using PostgreSQL

以下是我在pgAdmin中创建的功能:

CREATE OR REPLACE FUNCTION public.create_patient(
      patient_id integer,
      name character varying,
      sex character varying,
      "DOB" date,
      phone_number character varying,
      address character varying)
  RETURNS integer AS
$BODY$
begin
  INSERT INTO patient
    ("patient_id","name","sex","DOB","phone_number","address")
  VALUES 
    (patient_id,name,sex,DOB,phone_number,address);
  return patient_id;
end;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;

但是,当我调用下面的函数时:

SELECT create_patient(nextval('patient_sequence'),'tina','female','2016-12-06','7863334444','541 sw 3 st');

我收到以下错误消息:

ERROR:  function create_patient(bigint, unknown, unknown, unknown, unknown, unknown) does not exist
LINE 1: SELECT create_patient(nextval('patient_sequence'),'tina','fe...
               ^
    HINT:  No function matches the given name and argument types. You might need to add explicit type casts.

如何更改功能以有效插入值?

我的猜测是您的序列是bigint,但是您可以使用Patient_id作为整数来使用函数。 将序列更改为整数或将序列结果转换为整数:

SELECT create_patient(nextval('patient_sequence')::int,'tina','female',
    '2016-12-06','7863334444','541 sw 3 st');

无关紧要的是,由于您引用了DOB列,因此在使用它时会期望使用引号和文字大写上下文。 因此,我认为您可能需要将功能更改为此(请参见评论):

CREATE OR REPLACE FUNCTION create_patient(
  patient_id integer,  -- change this to a bigint if you don't want the cast
  name character varying,
  sex character varying,
  "DOB" date,
  phone_number character varying,
  address character varying) RETURNS integer AS
$BODY$
begin
  INSERT INTO patient(
    "patient_id",
    "name",
    "sex",
    "DOB",
    "phone_number",
    "address")
  VALUES (patient_id,
    name,
    sex,
    "DOB",   -- right here
    phone_number,
    address);
  return patient_id;
end;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;

我不确定100%,但是如果此修复不能解决所有问题,请注意。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM