所以当我将行插入名为'auxi'的表中时,我有以下函数触发器调用。它似乎不起作用,因为我的表上有值为'id_usuario'的NULL,并且触发器应该避免这种情况。
CREATE OR REPLACE FUNCTION firstRestriction() RETURNS Trigger
AS $$
DECLARE
operation boolean = false;
BEGIN
RAISE NOTICE 'HERE %',operation;
operation = operation OR isNULL(new.periodo, 'periodo');
operation = operation OR isNULL(new.id_usuario, 'id_usuario');
operation = operation OR isNULL(new.fecha_hora_retiro, 'fecha_hora_retiro');
operation = operation OR isNULL(new.origen_estacion, 'origen_estacion');
operation = operation OR isNULL(new.destino_estacion, 'destino_estacion');
operation = operation OR isNULL(new.tiempo_uso, 'tiempo_uso');
/*operation = operation OR isLessThanZero(new.tiempo_uso, 'tiempo_uso');*/
IF operation THEN
raise notice 'No se pudo insertar % % % % % %',new.periodo, new.id_usuario, new.fecha_hora_retiro,new.origen_estacion
,new.destino_estacion, new.tiempo_uso;
return NULL;
ELSE
return new;
END IF;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER checkFirstRestriction
BEFORE INSERT ON auxi
FOR EACH ROW
EXECUTE PROCEDURE firstRestriction();
然后我做
CREATE OR REPLACE FUNCTION cond1()
RETURNS VOID AS $$
BEGIN
INSERT INTO auxi
SELECT *
FROM datos_recorrido;
END;
$$ LANGUAGE PLPGSQL;
isNull也是以下函数
CREATE OR REPLACE FUNCTION isNULL(field anyelement, information TEXT) RETURNS boolean
AS $$
BEGIN
IF field IS NULL THEN
raise notice 'El campo % es NULL', information;
return true;
ELSE
return false;
END IF;
END;
$$ LANGUAGE plpgsql;
然后在某些时候我打电话给我的功能cond1()。 我认为我的触发器永远不会被调用。这有可能吗?