intermediateTop 30 Scenario-Based Questions
A PostgreSQL sequence is out of sync after a bulk INSERT using explicit IDs. How do you fix it?
Check current sequence value: SELECT last_value FROM employees_emp_id_seq; Check max ID in table: SELECT MAX(emp_id) FROM employees; Reset sequence to match: SELECT setval('employees_emp_id_seq', (SELECT MAX(emp_id) FROM employees)); Or to set next value: SELECT setval('employees_emp_id_seq', (SELECT MAX(emp_id) FROM employees), true); -- true = last_value (next INSERT will be max+1). In PostgreSQ
This is a Pro chapter
Sign in, then upgrade to Pro or Power to unlock this and the full Databases Mastery library.
A PostgreSQL sequence is out of sync after a bulk INSERT using explicit IDs. How do you fix it?