Re: Problemilla con funcion/trigger

From: Manuel Sugawara <masm(at)fciencias(dot)unam(dot)mx>
To: "Leo Gamez CCD Desarrollo" <desarrollo(at)ccdasesores(dot)e(dot)telefonica(dot)net>
Cc: <pgsql-es-ayuda(at)postgresql(dot)org>
Subject: Re: Problemilla con funcion/trigger
Date: 2005-04-12 17:10:26
Message-ID: m3oecjncot.fsf@conexa.fciencias.unam.mx
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

"Leo Gamez CCD Desarrollo" <desarrollo(at)ccdasesores(dot)e(dot)telefonica(dot)net> writes:

> CREATE FUNCTION INM_ORDENFOTO() RETURNS trigger AS '
> DECLARE
> sql varchar;
> BEGIN
> --Insert/Update
> IF NEW.ORDEN = 0 THEN --Foto de tipo Web
> IF TG_OP = ''UPDATE'' THEN
> sql := ''SELECT kfoto FROM inm.foto WHERE kpropiedad=''||
> NEW.kpropiedad || '' AND orden=0 AND kfoto<>'' || NEW.kfoto ;
> FOR fotosweb IN sql LOOP
> UPDATE inm.foto SET orden = 1 WHERE kfoto = fotosweb.kfoto;
> END LOOP;
> END IF;
> END IF;
> RETURN NEW;
> END; ' LANGUAGE plpgsql;

Dos comentarios, en el for te hace falta declarar fotosweb y tienes
que decir execute cuando estas generando la consulta de forma
dinámica:

declare
fotosweb record;
begin
FOR fotosweb IN execute sql LOOP
...

Saludos,
Manuel.

In response to

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Julio Rivero 2005-04-12 17:35:42 Re: RE: [pgsql-es-ayuda] Información
Previous Message Leo Gamez CCD Desarrollo 2005-04-12 16:45:10 Problemilla con funcion/trigger