Last active
August 29, 2015 14:15
-
-
Save dpirotte/c3dfc649d18e58f5cee6 to your computer and use it in GitHub Desktop.
Function to return all your postgres sequences and their last value
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 sequence_positions(OUT sequence_name regclass, OUT last_value bigint) returns setof record as $$ | |
declare | |
sequence regclass; | |
begin | |
FOR sequence IN SELECT format('%s.%s', n.nspname, c.relname) AS sequence FROM pg_class c JOIN pg_namespace n ON (c.relnamespace = n.oid) WHERE (c.relkind = 'S') | |
LOOP | |
return query execute format('select ''%s''::regclass, last_value from %s', sequence, sequence); | |
END LOOP; | |
end | |
$$ language plpgsql; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment