From: Adelo Herrero Pérez <adelo.herrero@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Control reached end of trigger procedure without RETURN
Date: Sat, 22 Jan 2011 10:37:01 +0100
Message-ID: <D3984DA4-FA99-4D3F-8091-1273FC9D8EED@gmail.com> (raw)
Buenos días:
Tengo una función que se dispara en un trigger cuya finalidad es; crear un registro en otra tabla o actualizarlo y devolviendo el id del registro creado/modificado para guardarlo en la tabla desde la que se llama. Intentaré explicarlo mejor:
tablaA --> Es la que dispara el trigger y en la que quiero guardar el id del registro modificado / creado en la tabla B.
tablaB --> Digamos que es una tabla resumen de la tablaA y se mantiene desde el trigger de la misma, creando modificando y/o borrando los registros.
Finalidad --> Eso, actualizar la tablaB desde la A y guardar en el registro de de la tablaA a que registro de la tablaB "pertenece".
Cuando hago el insert me devuelve el error del asunto
Control reached end of trigger procedure without RETURN
y me indica la línea correspondiente al INSERT.
¿Acaso no continúa el flujo if (not found) y debería hacer el return NEW tras el insert? ¿y lo mismo en el update del exception?
Agradezco de antemano vuestro tiempo y ayudas.
Un saludo.
P.D. Estructura de la función.
DECLARE
id_tablaB integer; -- Id de la tabla B.
BEGIN
IF (TG_OP = 'DELETE') THEN
-- Descontar valores
ELSIF (TG_OP = 'UPDATE') THEN
-- Modificar valores.
ELSIF (TG_OP = 'INSERT') THEN
-- Asignar valores
END IF;
-- Update con nuevos valores y retornamos el id para actualizar detalle.
UPDATE tablaB
SET campo1=valor1,
campo2=valor2
WHERE tablaA_id=NEW.tblaB_id
RETURNING tablaB_id INTO id_tablaB;
-- Si no existe, hacemos el insert y retornamos el id para actualizar detalle.
IF (NOT FOUND) THEN
BEGIN -- No existÌa el registro y lo creamos.
--
-- AQUÍ DEVUELVEL EL ERROR.
--
INSERT INTO tablaB (
campo1,
campo2)
VALUES ( valor1,
valor2 )
RETURNING tablaB_id INTO id_tablaB;
EXCEPTION
WHEN UNIQUE_VIOLATION THEN
UPDATE tablaB
SET campo1=valor1,
campo2=valor2
WHERE tablaA_id=NEW.tblaB_id
RETURNING tablaB_id INTO id_tablaB;
END;
END IF;
-- Borrado de ventas_imp si el resumen del % y factura es 0.
DELETE FROM tablaB
WHERE tablaA_id=id_tablaA AND (campo3=0 OR campo3 IS NULL);
-- Guardamos el id de la tabla ventas_imp y retornamos el record modificado.
NEW.tablaB_id := id_tablaB
return NEW;
END
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: adelo.herrero@gmail.com
Subject: Re: Control reached end of trigger procedure without RETURN
In-Reply-To: <D3984DA4-FA99-4D3F-8091-1273FC9D8EED@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox