Temat: Trigger AFTER INSERT, porównywanie danych z tabeli
CREATE OR REPLACE FUNCTION tcphdr_procedure()
RETURNS trigger AS
$BODY$
DECLARE
result BIGINT;
counter INTEGER;
BEGIN
IF (TG_OP= 'INSERT') THEN
SELECT connections.id INTO result FROM connections,tcp_connections WHERE
tcp_connections.cid = NEW.cid AND tcp_connections.src_ip=connections.src_addr
AND tcp_connections.dst_ip=connections.dst_addr
AND tcp_connections.src_port = connections.src_port
AND tcp_connections.tcp_dport = connections.dst_port;
IF FOUND THEN
INSERT INTO test_new VALUES(result);
RETURN NULL;
END IF;
END IF;
RETURN NULL; -- result is ignored since this is an AFTER trigger
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE
COST 100;