Skip to content

Instantly share code, notes, and snippets.

@redsfyre
Created March 23, 2022 08:05
Show Gist options
  • Save redsfyre/2c3c0cc199bac456673f28d461f41aa1 to your computer and use it in GitHub Desktop.
Save redsfyre/2c3c0cc199bac456673f28d461f41aa1 to your computer and use it in GitHub Desktop.
List postgresql sequences. Actually i dont remember what is this query :D
select sequence_name, (xpath('/row/last_value/text()', xml_count))[1]::text::int as last_value
from (
select sequence_schema,
sequence_name,
query_to_xml(format('select last_value from %I.%I', sequence_schema, sequence_name), false, true, '') as xml_count
from information_schema.sequences
where sequence_schema = 'public'
) new_table order by sequence_name asc;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment