Failing backend on plpgsql function - Mailing list pgsql-bugs

From Ondrej Palkovsky
Subject Failing backend on plpgsql function
Date
Msg-id Pine.LNX.4.20.0105191304100.4305-100000@ondra.debian.cz
Whole thread Raw
Responses Re: Failing backend on plpgsql function  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-bugs
I have the following function. When the function is executed and it gets
to the 'IF NOT FOUND', the backend gets restarted. I've read that the
exception handling is not perfect in Postgres but this seems to me
too hard behaviour for a badly written function.

CREATE FUNCTION attach_message(int8,int4,text[],date)
RETURNS int4
AS '
DECLARE
  v_msgid ALIAS FOR $1;
  v_folderid ALIAS FOR $2;
  v_flags ALIAS FOR $3;
  v_date ALIAS FOR $4;
  v_newuid int4;
  v_olduid int4;
BEGIN
  SELECT into v_newuid nextuid FROM folder WHERE folderid=v_folderid FOR
UPDATE;
  SELECT into v_olduid uid FROM msg_folder WHERE msgid=v_msgid AND
folderid=v_folderid;
  IF NOT FOUND THEN
    INSERT INTO msg_folder values
(v_msgid,v_folderid,v_newuid,v_internaldate,v_flags);
    UPDATE folder SET nextuid=nextuid+1 WHERE folderid=v_folderid;
    return v_newuid;
  END IF;
  return v_olduid;
end;
' LANGUAGE 'plpgsql';


--
As President I have to go vacuum my coin collection!

pgsql-bugs by date:

Previous
From: "Alexander Zagrebin"
Date:
Subject: bug in plpgsql???
Next
From: "karthikeyan V"
Date:
Subject: pg_dumpall in post