Created
March 30, 2012 23:02
-
-
Save maxjustus/2257305 to your computer and use it in GitHub Desktop.
dynamic insertion into partition based on value in insert for Postgres
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
create or replace function insert_herp_to_derp() | |
returns trigger as $$ | |
begin | |
execute 'INSERT INTO ' || quote_ident('derp_' || NEW.derp_id || '_herps') || ' SELECT ($1).*' using NEW; | |
return null; | |
end; | |
$$ LANGUAGE plpgsql; | |
CREATE TRIGGER insert_herps_trigger BEFORE INSERT ON herps FOR EACH ROW EXECUTE PROCEDURE insert_herp_to_derp(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment