catch postgresql exceptions when a foreingkey not exist in the table with which it interacts.
CREATE OR REPLACE FUNCTION calculo_pensionado_prueba(text)
RETURNS text AS
$BODY$
DECLARE
mensaje TEXT;
ultimo_registro INTEGER;
BEGIN
BEGIN
RAISE NOTICE 'inicia';
ultimo_registro = (SELECT CASE WHEN max(id) NOTNULL
THEN max(id) + 1 ELSE 1 END FROM calculonomina_periodo_calculo_temp);
INSERT INTO calculonomina_periodo_calculo_temp VALUES (ultimo_registro, 330, 10.00, 10.00, 100,NULL, 15, 569, 501, 183, '{"monto":"hola"}', 9135, 35, 1, 1, 124, 56, 'Pensionado');
--RAISE NOTICE 'despues del insert';
--EXECUTE 'DROP TABLE ' || $1;
EXCEPTION
WHEN FOREIGN_KEY_VIOLATION THEN
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 293 |
Nodes: | 16 (2 / 14) |
Uptime: | 220:26:08 |
Calls: | 6,622 |
Calls today: | 4 |
Files: | 12,171 |
Messages: | 5,318,027 |