dbTalk Databases Forums  

[SQL] Control reached end of trigger procedure without RETURN

mailing.database.pgsql-sql mailing.database.pgsql-sql


Discuss [SQL] Control reached end of trigger procedure without RETURN in the mailing.database.pgsql-sql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
MoNiLlO
 
Posts: n/a

Default [SQL] Control reached end of trigger procedure without RETURN - 01-22-2011 , 12:32 AM






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 registrode 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 returnNEW 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



--
Sent via pgsql-sql mailing list (pgsql-sql (AT) postgresql (DOT) org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.