Today I was trying to figure out the name of a sequence in the db, so I could add it to my hibernate mapping. I usually use pgAdmin, but that wasn’t an option today. After some searching, I eventually figured it out, but it took me awhile…
Get a list of all Sequences in a schema:
select sequence_name from information_schema.sequences where sequence_schema='public'
Get a list of all tables:
select table_name from information_schema.tables where table_schema='public'
Get the next sequence value for sequence: foo_seq
SELECT setval('foo_seq', 42);
Update the sequence to 42 for sequence: foo_seq
Note if you are looking for more info on sequences check here: Sequence-Manipulation Functions