From 49990be9be4f23e605c43be585a7895fe56ab181 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Mon, 13 Feb 2023 10:33:28 -0700 Subject: [PATCH] silently discard insert --- .../059_node_insert_trigger_rewrite.sql | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/data_access_layer/migrations/059_node_insert_trigger_rewrite.sql diff --git a/src/data_access_layer/migrations/059_node_insert_trigger_rewrite.sql b/src/data_access_layer/migrations/059_node_insert_trigger_rewrite.sql new file mode 100644 index 000000000..a1c5e69cd --- /dev/null +++ b/src/data_access_layer/migrations/059_node_insert_trigger_rewrite.sql @@ -0,0 +1,32 @@ +CREATE OR REPLACE FUNCTION node_insert_trigger() RETURNS TRIGGER AS $$ +DECLARE + old_id bigint; + old_properties jsonb; +BEGIN + IF NEW.original_data_id IS NOT NULL THEN + BEGIN + SELECT nodes.id, nodes.properties + INTO old_id, old_properties + FROM nodes + WHERE original_data_id = NEW.original_data_id + AND metatype_id = NEW.metatype_id + AND data_source_id = NEW.data_source_id LIMIT 1; + EXCEPTION + WHEN NO_DATA_FOUND THEN + old_id := NULL; + END; + + IF old_id IS NOT NULL THEN + NEW.id = old_id; +/* + if the old properties are exactly the same as the new properties, silently discard the insert + */ + IF old_properties IS NOT DISTINCT FROM NEW.properties THEN + RETURN NULL; + END IF; + END IF; + END IF; + + RETURN NEW; +END; +$$ language plpgsql; \ No newline at end of file