hi, i'm trying the following procedure/triger to obtain values for some
fields in the newly inserted records:
------------------------------------------------------------------------
-- procedimiento y trigger para obtener los precios
-- a pagar en base a las opciones de curso, turno, semestre
-- y sistema elegidos
-- eliminamos versiones anteriores
DROP TRIGGER trigger_fichas ON fichas;
DROP FUNCTION trigger_ins_act_fichas();
CREATE FUNCTION trigger_ins_act_fichas()
RETURNS opaque
AS '
DECLARE
registro RECORD;
BEGIN
IF NEW.inscripcion = 0 THEN
SELECT * INTO registro
FROM precios
WHERE NEW.curso = registro.curso AND
NEW.sistema = registro.sistema AND
NEW.turno = registro.turno AND
NEW.semestre = registro.semestre;
IF NOT FOUND THEN
RAISE EXCEPTION ''No hay curso registrado.'';
ELSE
NEW.curso := registro.curso;
NEW.sistema := registro.sistema;
NEW.turno := registro.turno;
NEW.semestre := registro.semestre;
END IF;
END IF;
RETURN NEW;
END;'
LANGUAGE 'plpgsql';
CREATE TRIGGER trigger_fichas
BEFORE INSERT OR UPDATE
ON fichas
FOR EACH ROW
------------------------------------------------------------------------
but every time i insert a new record, it says something like:
"ERROR record registro not assigned yet"
it happens inserting in psql and from a java app, some ideas about
what's wrong :(
thanks in advance