postgres函数类型的输入语法无效

时间:2014-07-11 13:00:17

标签: sql function postgresql

我有这个功能:

CREATE OR REPLACE FUNCTION year_2014.insertsub
(
  accountid      integer,
  analyseid      integer,
  analysedate    date,
  requestnumber  integer
)
RETURNS integer AS
$$
DECLARE r integer;
begin
FOR r IN SELECT public."SubAnalyze".id FROM  public."SubAnalyze" where public."SubAnalyze".analyze_id = analyseid
loop
   INSERT INTO year_2014."Results"(account_id, analyze_id, "date", subanalyze_id, requestnumber)
VALUES
    (accountid, analyseid, 'analysedate', r, requestnumber);
END LOOP;
RETURN 1; 
end
$$
LANGUAGE 'plpgsql'
VOLATILE
CALLED ON NULL INPUT
SECURITY INVOKER
COST 100;

ALTER FUNCTION year_2014.insertsub(accountid integer, analyseid integer, analysedate date, requestnumber integer)
  OWNER TO postgres;

当我运行函数错误消息

SQL错误:错误:类型为date的输入语法无效:" analysedate" 第3行:( accountid,analyseid,' analysedate',r,requestnumber)                                    ^ QUERY:INSERT INTO year_2014。" Results"(account_id,analyze_id," date",subanalyze_id,requestnumber) VALUES     (accountid,analyseid,' analysedate',r,requestnumber) 语境:PL / pgSQL函数year_2014.insertsub(整数,整数,日期,整数)第6行SQL语句

1 个答案:

答案 0 :(得分:0)

请不要引用“分析”,以这种方式将文本analysedate发送到您的插入命令而不是日期,正确的语法是:

INSERT INTO year_2014."Results"(account_id, analyze_id, "date", subanalyze_id, requestnumber)
VALUES
(accountid, analyseid, analysedate, r, requestnumber);