Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Postgresql url partition scheme action trigger function
CREATE OR REPLACE FUNCTION url_insert_trigger()
RETURNS TRIGGER AS $$
BEGIN
IF (ascii(NEW.url) in (115)) THEN
INSERT INTO urls_s VALUES (NEW.*);
ELSIF (ascii(NEW.url) in (97, 107)) THEN
INSERT INTO urls_ak VALUES (NEW.*);
ELSIF (ascii(NEW.url) in (98, 108)) THEN
INSERT INTO urls_bl VALUES (NEW.*);
ELSIF (ascii(NEW.url) in (99, 106)) THEN
INSERT INTO urls_cj VALUES (NEW.*);
ELSIF (ascii(NEW.url) in (100, 101)) THEN
INSERT INTO urls_de VALUES (NEW.*);
ELSIF (ascii(NEW.url) in (102, 103)) THEN
INSERT INTO urls_fg VALUES (NEW.*);
ELSIF (ascii(NEW.url) in (104, 105, 118)) THEN
INSERT INTO urls_hiv VALUES (NEW.*);
ELSIF (ascii(NEW.url) in (109, 114)) THEN
INSERT INTO urls_mr VALUES (NEW.*);
ELSIF (ascii(NEW.url) in (110, 112)) THEN
INSERT INTO urls_np VALUES (NEW.*);
ELSIF (ascii(NEW.url) in (116, 120, 122, 121, 111)) THEN
INSERT INTO urls_txzyo VALUES (NEW.*);
ELSIF (ascii(NEW.url) in (117, 119, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 113)) THEN
INSERT INTO urls_uw0123456789q VALUES (NEW.*);
ELSE
RAISE EXCEPTION 'url out of range. Fix the url_insert_trigger() function!';
END IF;
RETURN NULL;
END;
$$
LANGUAGE plpgsql;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.