Created
February 28, 2017 06:11
-
-
Save saicitus/74e6de56b77a26d22cc576004d8242b1 to your computer and use it in GitHub Desktop.
This file contains 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
CREATE TABLE key_value (key int, value jsonb); | |
CREATE TABLE big_table(key int, first_name text, last_name text); | |
select create_distributed_table('key_value','key'); | |
select create_distributed_table('big_table','key'); | |
select run_command_on_shards($cmd$big_table$cmd$,$cmd$CREATE OR REPLACE FUNCTION insert_fun_%1$I() RETURNS TRIGGER AS $$ | |
BEGIN | |
-- | |
-- Perform the required operation on emp, and create a row in emp_audit | |
-- to reflect the change made to emp. | |
-- | |
IF (TG_OP = 'INSERT') THEN | |
INSERT INTO %1$I(key,first_name,last_name) VALUES(NEW.key,NEW.value->>'first_name'',NEW.value->>'last_name'); | |
END IF; | |
RETURN NULL; | |
END; | |
$$ LANGUAGE plpgsql;$cmd$); | |
select run_command_on_colocated_placements($cmd$key_value$cmd$,$cmd$big_table$cmd$,$cmd$CREATE TRIGGER after_insert AFTER INSERT ON %I FOR EACH ROW EXECUTE PROCEDURE insert_fun_%I()$cmd$); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment