Hola, beun día
Tengo un problema con una función, que al ejecutarse por un Trigger devuelve NULL y no encuentro la razón. --- CREATE OR REPLACE FUNCTION "public"."actua_desref" () RETURNS trigger AS $BODY$ DECLARE empeno record; fechahoy date; fechaven date; diasm int; inmo float; BEGIN IF TG_OP='INSERT' THEN IF (NEW.tipo = 1 AND NEW.concepto = 1) OR (NEW.tipo = 1 AND NEW.concepto = 2) THEN SELECT INTO empeno fecha_venta, prestamo FROM empenos WHERE id=NEW.id; fechahoy = current_date; fechaven = TIMESTAMP WITH TIME ZONE 'epoch' + empeno.fecha_venta * INTERVAL '1 second'; diasm = fechahoy - fechaven; inmo = ((0.5 * empeno.prestamo::float)/100) * diasm; NEW.cantidad = NEW.cantidad::float + inmo; return NEW; END IF; END IF; END $BODY$ LANGUAGE 'plpgsql' --- CREATE TRIGGER "calc_inmo" BEFORE INSERT ON caja FOR EACH ROW EXECUTE PROCEDURE actua_desref() --- Al hacer un Insert Obtengo un: SQL Error: ERROR: null value in column cantidad violates not-null constraint. Esto me idica que el registro que regresa la funcion trae el campo cantidad a NULL, y no deberia ser así. Adicional a esto tengo una funcion que hice para probar que todo funcione correctamente (independientemente de esta) y al llamarla si me ejecuta correctamente: --- CREATE OR REPLACE FUNCTION "public"."pruebas" () RETURNS float8 AS $BODY$ DECLARE empeno record; fechahoy date; fechaven date; diasm int; inmo float; BEGIN SELECT INTO empeno fecha_venta, prestamo FROM empenos WHERE id=1618; fechahoy = current_date; fechaven = TIMESTAMP WITH TIME ZONE 'epoch' + empeno.fecha_venta * INTERVAL '1 second'; diasm = fechahoy - fechaven; inmo = ((0.5 * empeno.prestamo::float)/100) * diasm; return inmo; END $BODY$ LANGUAGE 'plpgsql' --- Alguna sugerencia? Gracias!!! Saluos!