From: | "Jaime Casanova" <systemguards(at)gmail(dot)com> |
---|---|
To: | "Alejandro Gasca" <agasca(at)yahoo(dot)com> |
Cc: | "ayuda postgres" <pgsql-es-ayuda(at)postgresql(dot)org> |
Subject: | Re: duda con 'Example 37-3' del manual para version 8.2.1 |
Date: | 2007-02-13 01:23:09 |
Message-ID: | c2d9e70e0702121723u2e07e059t7e015df8077f45d2@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-es-ayuda |
On 2/12/07, Alejandro Gasca <agasca(at)yahoo(dot)com> wrote:
> Saludos.
>
> En el manual, en la seccion de triggers escritos en plpgsql viene un ejemplo de un trigger:
>
> CREATE OR REPLACE FUNCTION process_emp_audit() RETURNS TRIGGER AS $emp_audit$
> BEGIN
> --
> -- Create a row in emp_audit to reflect the operation performed on emp,
> -- make use of the special variable TG_OP to work out the operation.
> --
> IF (TG_OP = 'DELETE') THEN
> INSERT INTO emp_audit SELECT 'D', now(), user, OLD.*;
> RETURN OLD;
> ELSIF (TG_OP = 'UPDATE') THEN
> INSERT INTO emp_audit SELECT 'U', now(), user, NEW.*;
> RETURN NEW;
> ELSIF (TG_OP = 'INSERT') THEN
> INSERT INTO emp_audit SELECT 'I', now(), user, NEW.*;
> RETURN NEW;
> END IF;
> RETURN NULL; -- result is ignored since this is an AFTER trigger
> END;
> $emp_audit$ LANGUAGE plpgsql;
>
> CREATE TRIGGER emp_audit
> AFTER INSERT OR UPDATE OR DELETE ON emp
> FOR EACH ROW EXECUTE PROCEDURE process_emp_audit();
>
> Alguien sabe bajo que condiciones se ejecuta el RETURN NULL ? Al correr el ejemplo no veo como se puede llegar a esta linea.
>
bajo ninguna condicion, esta ahi solo para enseñarte que lo mejor es
programar a la defensiva ;) (imagino que es cuestion de gustos poner
el return null en ese caso)
--
Atentamente,
Jaime Casanova
"Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs and the universe trying
to produce bigger and better idiots.
So far, the universe is winning."
Richard Cook
From | Date | Subject | |
---|---|---|---|
Next Message | JOSE ALBERTO NUÑEZ MORENO | 2007-02-13 04:44:32 | Licencia |
Previous Message | Jaime Casanova | 2007-02-13 01:18:08 | Re: diferencia entre := y = en plpgsql |