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!