Update en trigger disparado por update. Es recursivo?

From: Sebastián Villalba <sebastian(at)fcm(dot)unc(dot)edu(dot)ar>
To: "Lista Ayuda Pgsql" <pgsql-es-ayuda(at)postgresql(dot)org>
Subject: Update en trigger disparado por update. Es recursivo?
Date: 2005-07-13 16:21:09
Message-ID: 20050713155744.M75357@fcm.unc.edu.ar
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

Hola amigos. Antes que me olvide. Tengo Postgres 8.03 en Linux.
Tengo un trigger que controla que cuando se actualice un campo en una tabla,
ese campo sea como máximo igual a otro valor de campo de otra tabla. Entonces
hice la siguiente función (volatil) que retorna un trigger:

CREATE OR REPLACE FUNCTION "tg_updateCupoCursoPerfil"() RETURNS trigger AS $$
DECLARE
recCurso RECORD;
BEGIN
SELECT INTO recCurso * FROM cursos WHERE id = new.curso_id;
IF (new.cupo > recCurso.cupo) THEN
new.cupo = recCurso.cupo;
END IF;
UPDATE cupocursoperfil SET cupo = new.cupo WHERE new.perfil_id =
old.perfil_id AND new.curso_id = old.curso_id;
RETURN NULL;
END;
$$ LANGUAGE plpgsql VOLATILE SECURITY DEFINER

El trigger es el siguiente:

CREATE TRIGGER tg_updatecupocursoperfil BEFORE UPDATE ON cupocursoperfil FOR
EACH ROW EXECUTE PROCEDURE "tg_updateCupoCursoPerfil"()

El error que me dá es el siguiente (repitiéndose muuuchas veces la última parte):

ERROR: stack depth limit exceeded
HINT: Increase the configuration parameter "max_stack_depth".
CONTEXT: SQL statement "SELECT * from cursos where id = $1 "
PL/pgSQL function "tg_updateCupoCursoPerfil" line 4 at select into variables
SQL statement "update cupocursoperfil set cupo = $1 where $2 = $3 and
$4 = $5 "
PL/pgSQL function "tg_updateCupoCursoPerfil" line 8 at SQL statement
SQL statement "update cupocursoperfil set cupo = $1 where $2 = $3 and
$4 = $5 "
PL/pgSQL function "tg_updateCupoCursoPerfil" line 8 at SQL statement
SQL statement "update cupocursoperfil set cupo = $1 where $2 = $3 and
$4 = $5 "
PL/pgSQL function "tg_updateCupoCursoPerfil" line 8 at SQL statement
SQL statement "update cupocursoperfil set cupo = $1 where $2 = $3 and
$4 = $5 "

Saludos...

-
-------------------------------------------
Sebastián Villalba
sebastian(at)fcm(dot)unc(dot)edu(dot)ar
-------------------------------------------

Responses

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Sebastián Villalba 2005-07-13 16:42:11 Re: Update en trigger disparado por update. Es recursivo?
Previous Message Wilmer Mendoza 2005-07-13 16:15:28 busqueda