0

I have to create a update procedure, so i created a function and given only below query

 CREATE FUNCTION public.testf()
    RETURNS boolean
    LANGUAGE 'plpgsql'

AS $BODY$begin
update tt pp
set status  = 'Ok'
return true;
end;$BODY$;

ALTER FUNCTION public.testf()
    OWNER TO postgres;

returns error

ERROR: syntax error at or near "UPDATE" LINE 5: AS $BODY$UPDATE

return type I have given is int4range

What I am doing wrong

Please help THanks

5
  • Please post the entire definition of the procedure Commented May 11, 2020 at 12:41
  • i have only this line Commented May 11, 2020 at 12:41
  • 1
    That's not a procedure/function, that's a single SQL query. Post the complete code. Commented May 11, 2020 at 12:42
  • Also, is your table really named table? That might cause issues, as it is a keyword. Use UPDATE "table" … Commented May 11, 2020 at 12:42
  • code updated now Commented May 11, 2020 at 13:02

2 Answers 2

2

Pulling out my crystal ball, I see:

  • You created the function with LANGUAGE plpgsql.

  • You didn't surround the function body with BEGIN ... END;.

If your function is just a single SQL statement, use LANGUAGE sql.

Else, use the block-centered PL/pgSQL syntax properly.

Sign up to request clarification or add additional context in comments.

4 Comments

Ok, my crystal ball cannot penetrate that deep. You'll have to edit the question and show the complete function and the error message.
I think you hit the nail on the head, and the next error message will be that neither implementation will return a int4range.
Yes. Where should that int4rangecome from?
I have updated post whatever its showing in sql tab
1

You are missing an ; to end the UPDATE statement.

CREATE FUNCTION public.testf()
    RETURNS boolean
    LANGUAGE plpgsql
AS $BODY$
begin
  update tt pp
    set status  = 'Ok';  --<< here

  return true;
end;
$BODY$;

Comments

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.