Created
March 1, 2017 09:33
-
-
Save stelf/8b234393adc5ef453a810c34a2947c03 to your computer and use it in GitHub Desktop.
update all sequences with some value in postgresql
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 update_all_seqs(inc integer) returns void as $$ | |
DECLARE | |
r pg_class%rowtype; | |
i name; | |
isit integer; | |
BEGIN | |
FOR i in SELECT c.relname from pg_class c where c.relkind = 'S' LOOP | |
isit := POSITION('pv_' in i); | |
IF (isit = 1) THEN | |
execute 'select last_value from visionr.' || i into isit; | |
execute 'alter sequence visionr.' || i || ' restart with ' || (isit+inc); | |
RAISE NOTICE 'update d(%)', i::varchar; | |
END IF; | |
END LOOP; | |
END; | |
$$ LANGUAGE plpgsql; | |
select f(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment