Обсуждение: Failing backend on plpgsql function

Поиск
Список
Период
Сортировка

Failing backend on plpgsql function

От
Ondrej Palkovsky
Дата:
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!

Re: Failing backend on plpgsql function

От
Tom Lane
Дата:
Ondrej Palkovsky <xpalo03@vse.cz> writes:
> I have the following function. When the function is executed and it gets
> to the 'IF NOT FOUND', the backend gets restarted.

Is this in 7.1.1?  There's an embarrassing bug in 7.1.1 --- plpgsql
coredumps on a SELECT that returns no rows.  It's fixed for 7.1.2.

            regards, tom lane