Raise Exception

From: "Mauricio E(dot) Pastorini Torres" <m_pastorini(at)elgolfo(dot)cl>
To: pgsql-es-ayuda(at)postgresql(dot)org
Subject: Raise Exception
Date: 2004-04-28 20:24:56
Message-ID: 25224.200.50.110.187.1083183896.squirrel@www.elgolfo.cl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

Estimados amigos... he construido una funcion que necesita actualizar
varias tablas tal como lo muestro en el siguiente ejemplo...

CREATE FUNCTION actualiza() RETURNS trigger AS '
BEGIN

update cargas set codtitular = new.codpaciente where codtitular =
old.codpaciente;

if (variable_de_error) then
raise exception 'error al actualizar cargas';
end if

update paciente_historia_clinica set codpaciente = new.codpaciente
where codpaciente = old.codpaciente;

if (variable_de_error) then
raise exception 'error al actualizar historia clinica';
end if

update pac_emp set codpaciente = new.codpaciente where codpaciente
= old.codpaciente;

if (variable_de_error) then
raise exception 'error al actualizar pac_emp';
end if

RETURN NEW;
END;
' LANGUAGE plpgsql;

mi pregunta es... ¿cuál es la variable que verifica si existió o no un
error en la última instrucción sql?

y la segunda pregunta.... el mismo ejemplo:

CREATE FUNCTION actualiza() RETURNS trigger AS '
BEGIN
if old.codpaciente != new.copaciente then
update cargas set codtitular = new.codpaciente where codtitular
= old.codpaciente;

if (variable_de_error) then
raise exception 'error al actualizar cargas';
end if;

update paciente_historia_clinica set codpaciente =
new.codpaciente where codpaciente = old.codpaciente;

if (variable_de_error) then
raise exception 'error al actualizar historia clinica';
end if;

update pac_emp set codpaciente = new.codpaciente where
codpaciente = old.codpaciente;

if (variable_de_error) then
raise exception 'error al actualizar pac_emp';
end if;
end if;

RETURN NEW;
END;
' LANGUAGE plpgsql;

esta bien construido esto? lo pregunto por que al momento de compilarlo me
marco un error...

obs.: el procedimiento del ejemplo es activado por un trigger.

bueno espero haber sido claro en mi pregunta...

gracias

Mauricio Pastorini T.

In response to

Responses

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Alvaro Herrera 2004-04-28 22:00:05 Re: El postmaster esta levantado y no puedo entrar
Previous Message Martin Marques 2004-04-28 20:17:55 Re: Actualizar a 7.4.2