[Pgsql-ayuda] return new, return old, trigger
sandrigo lezcano
alkafes@yahoo.com
Tue, 12 Aug 2003 10:39:56 -0500 (CDT)
algun consejo sencillo para ayudarme a establecer
si mi retorno en una
function-trigger sea new o old ???
entiendo (creo... segun manual)
NEW: variable holding (..???) para operacion INSERT/UPDATE
en la nueva tupla ... ????
OLD: variable holding (..???) para operacion UPDATE/DELETE
en la ultima tupla (vieja) ..??
ej. (es un trigger migrado (o intento..) del sybase)
CREATE FUNCTION tub_personas () RETURNS TRIGGER AS '
begin
new.cedula := fn_quitar_puntos_de_cadena(new.cedula);
new.ruc := trim(new.ruc);
if length(new.ruc) = 0 then
new.ruc := null;
end if;
if update(cedula) then
if new.cedula is not null then
if exists(select 1 from personas where cedula = new.cedula)
then
RAISE EXCEPTION ''<*El Nro. de Cédula ya existe!!*>'';
end if;
end if;
end if;
if update(credito_maximo) then
if old.credito_disponible = old.credito_maximo then
new.credito_disponible := new.credito_maximo;
elseif old.credito_disponible < old.credito_maximo then
RAISE EXCEPTION ''<*El Crédito Disponible ha sido
utilizado, no puede modificar el Crédito Máximo*>'';
end if;
end if;
return new;
end;
CREATE TRIGGER tub_personas BEFORE UPDATE ON personas
FOR EACH ROW EXECUTE PROCEDURE tub_personas();
=====
-- ICQ Web-based!!
----------------------------------------------
Sandrigo Lezcano Jara ICQ: 143590717
Asuncion, Paraguay http://go.icq.com
_________________________________________________________
Do You Yahoo!?
Información de Estados Unidos y América Latina, en Yahoo! Noticias.
Visítanos en http://noticias.espanol.yahoo.com