From c76b9060accd45b984aa831a4b98d3109befd49f Mon Sep 17 00:00:00 2001
From: glyn <glyn@8kb.co.uk>
Date: Fri, 5 Dec 2014 18:22:49 +0000
Subject: [PATCH] Stop doing useless work

---
 pg_settings_history.plpgsql | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/pg_settings_history.plpgsql b/pg_settings_history.plpgsql
index 371b9f8..3c7102f 100755
--- a/pg_settings_history.plpgsql
+++ b/pg_settings_history.plpgsql
@@ -59,13 +59,17 @@ BEGIN
         
         GET DIAGNOSTICS v_changes = ROW_COUNT;
 
-        -- Update the snapshot ready for the next run.
-        TRUNCATE public.pg_settings_last;
-        INSERT INTO pg_settings_last (name, setting, unit, category, short_desc, extra_desc, context, vartype, source, min_val, 
+        IF (v_changes > 0) THEN
+            -- Update the snapshot ready for the next run.
+            TRUNCATE public.pg_settings_last;
+            INSERT INTO pg_settings_last (name, setting, unit, category, short_desc, extra_desc, context, vartype, source, min_val, 
                 max_val, enumvals, boot_val, reset_val, sourcefile, sourceline)
-        SELECT * FROM pg_settings;
-    
-        RETURN (v_changes > 0);
+            SELECT * FROM pg_settings;
+
+            RETURN true;
+   	ELSE 
+            RETURN false;
+	END IF; 
     END IF;    
 END;
 
-- 
2.39.5