Results 1 to 4 of 4
  1. #1
    Join Date
    May 2009
    Posts
    6

    Unanswered: problem with function

    Hello to everybody, I would like create a easy function for Postgresql 8.3 with pgadmin3, but always I get this message:
    An error has occurred:

    ERROR: syntax error at or near "IF"
    LINE 3: IF repetition=0 THEN date_for:= data + '1 day';
    ^
    this is my definition:

    BEGIN
    IF repetition=0 THEN date_for:= data + '1 day';
    ELSIF repetition=1 THEN date_for:=data::timestamp + '3 days'::interval;
    END IF;
    IF repetition < 4 THEN
    repetition:=repetition +1;
    END IF;
    return date_for,repetition;
    END;

    I do not understand what is the problem,
    Please help me, thanks in advance.

  2. #2
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    You are missing the "CREATE FUNCTION" part and you don't declare the variables you are using.

    return date_for,repetition;
    Additionally: you cannot return more than one value from a function
    Last edited by shammat; 05-17-09 at 16:56.

  3. #3
    Join Date
    May 2009
    Posts
    6

    re-problem-with function

    hi I have changed the code:
    CREATE FUNCTION progression_job(IN data date, OUT date_for date, INOUT date_for integer) RETURNS record AS
    $BODY$
    BEGIN
    IF repetition=0 THEN date_for:= data + '1 day';
    ELSIF repetition=1 THEN date_for:=data::timestamp + '3 days'::interval;
    END IF;
    IF repetition < 4 THEN
    repetition:=repetition +1;
    END IF;
    return date_for,repetition;
    END;
    $BODY$
    LANGUAGE 'sql' VOLATILE;




    but it still returns me the same error message:


    ERROR: syntax error at or near "IF"
    LINE 4: IF repetition=0 THEN date_for:= data + '1 day';
    ^

    ********** Error **********

    ERROR: syntax error at or near "IF"
    SQL state: 42601
    Character: 121

  4. #4
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    The semicolon at the end of the IF is wrong.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •