0

I have this Function:

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;

when I run the function error message

SQL Error: ERROR: invalid input syntax for type date: "analysedate" LINE 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) CONTEXT: PL/pgSQL function year_2014.insertsub(integer,integer,date,integer) line 6 at SQL statement

1 Answer 1

0

Don't quote 'analysedate', in this way you send the text analysedate to your insert command instead of a date, the correct syntax is:

INSERT INTO year_2014."Results"(account_id, analyze_id, "date", subanalyze_id, requestnumber)
VALUES
(accountid, analyseid, analysedate, r, requestnumber);
1
  • when I remove quote and run Function: SQL Error: ERROR: function year_2014.insertsub(integer, integer, integer, integer) does not exist LINE 1: SELECT * FROM year_2014.insertsub(7, 14, 12/12/2014, 9) LIMI... ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. Commented Jul 11, 2014 at 13:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.