SHARE
TWEET

Untitled

a guest Jan 25th, 2016 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. CREATE OR REPLACE FUNCTION synchronize()
  2. RETURNS trigger AS
  3. $$
  4.     import psycopg2
  5.  
  6.     conn = psycopg2.connect("host=... dbname=... user=... password=...")
  7.     cur = conn.cursor()
  8.  
  9.     # If inserting...
  10.     if TD['event'] == 'INSERT':
  11.       cur.execute(...)
  12.  
  13.     # If deleting...
  14.     if TD['event'] == 'DELETE':
  15.       cur.execute(...)
  16.  
  17.     conn.commit()
  18.     cur.close()
  19.     conn.close()
  20. $$
  21. LANGUAGE 'plpython2u' VOLATILE;
  22.    
  23. CREATE TRIGGER replica_insert
  24. AFTER INSERT ON users
  25. FOR EACH ROW
  26. EXECUTE PROCEDURE synchronize();
  27.  
  28. CREATE TRIGGER replica_delete
  29. BEFORE DELETE ON users
  30. FOR EACH ROW
  31. EXECUTE PROCEDURE synchronize();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top