Last active
August 29, 2015 13:57
-
-
Save fbeauchamp/9879820 to your computer and use it in GitHub Desktop.
typo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Function: agent_notify() | |
-- DROP FUNCTION agent_notify(); | |
CREATE OR REPLACE FUNCTION agent_notify() | |
RETURNS trigger AS | |
$BODY$ | |
DECLARE | |
diff hstore; | |
t text; | |
BEGIN | |
IF TG_OP= 'INSERT' | |
THEN diff = NEW.Attributes ; | |
ELSE diff = NEW.Attributes - OLD.attributes; | |
END IF ; | |
IF diff = hstore('') THEN | |
-- All changed fields are ignored. Skip this update. | |
RETURN NULL; | |
END IF; | |
diff = diff || hstore('id',CAST(NEW.id as text)); | |
PERFORM pg_notify('agent', | |
ARRAY_TO_STRING(ARRAY( | |
SELECT | |
(key || ':|:' || value) | |
FROM | |
EACH(diff) | |
), '*|*')) FROM agent; | |
RETURN NEW; | |
END; | |
$BODY$ | |
LANGUAGE plpgsql VOLATILE | |
COST 100; | |
ALTER FUNCTION agent_notify() | |
OWNER TO florent; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment