Skip to content

Useful Postgresql Commands (Add to this as you come across them please!)

Ryan edited this page Mar 3, 2018 · 1 revision

Use when your auto increment sequence goes out of sync.

SELECT setval('your_seq',(SELECT GREATEST(MAX(your_id)+1,nextval('your_seq'))-1 FROM your_table))

Clone this wiki locally