Re: Update en trigger disparado por update. Es recursivo?

From: Juan Pablo GO <mozstyle2002(at)gmx(dot)net>
To: Sebastián Villalba <sebastian(at)fcm(dot)unc(dot)edu(dot)ar>
Cc: Lista Ayuda Pgsql <pgsql-es-ayuda(at)postgresql(dot)org>
Subject: Re: Update en trigger disparado por update. Es recursivo?
Date: 2005-07-13 16:45:20
Message-ID: 42D54520.5050605@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

Independientemente del error del trigger, si entiendo bien, ¿por qué no
utilizas integridad referencial entre la tabla A y B?

Salu2
Juan Pablo GO

Sebastián Villalba wrote:

>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
>-------------------------------------------
>
>
>---------------------------(fin del mensaje)---------------------------
>TIP 1: para suscribirte y desuscribirte, escribe a majordomo(at)postgresql(dot)org
>
>
>
>

In response to

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Ivan Figueroa 2005-07-13 19:11:03 Re: Libreria C para acceder a MsSQL
Previous Message Alvaro Herrera 2005-07-13 16:43:53 Re: Update en trigger disparado por update. Es recursivo?