problem with triggers - Mailing list pgsql-general

From miguel angel rojas aquino
Subject problem with triggers
Date
Msg-id 3B66CEEC.F8F3D495@mail.flashmail.com
Whole thread Raw
Responses Re: problem with triggers  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
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


pgsql-general by date:

Previous
From: wsheldah@lexmark.com
Date:
Subject: Re: ODBC read/write permission in MS Access
Next
From: tankgirl@worldonline.es
Date:
Subject: Asking for some PL/pgSQL Tips