postgres add unique constraint code example
Example 1: postgres add unique constraint to column
ALTER TABLE table_name
ADD CONSTRAINT constraint_name UNIQUE (column1, column2, ... column_n);
Example 2: postgresql resolv duplicate value violates unique constraint
SELECT setval(pg_get_serial_sequence('users', 'id'), coalesce(max(id)+1, 1), false) FROM users;