title: SQL issue: Duplicate key value violates unique constraint
body: <p>I'm running Postgres10 on PGAdmin4</p>
  
  <p>To see if my database is out of sync, I'm checking my primary key and primary key sequence. </p>
  
  <p>I'm running this query to check primary key:</p>
  
  <ul>
  <li><p><code>MAX(sid) FROM schema_name.table_name;</code> Returns 1032</p>
  
  <ul>
  <li><p>sid is the primary key</p></li>
  <li><p>schema_name is the schema where my table is located</p></li>
  <li><p>table_name is name of the table where the unique constraint is being violated</p></li>
  </ul></li>
  </ul>
  
  <p>I'm running this query to check primary key sequence:</p>
  
  <ul>
  <li><code>SELECT nextval(pg_get_serial_sequence('schema_name.table_name', 'sid'));</code> returns 1042 (current value is 1041).</li>
  </ul>
  
  <p>Referencing this SO: I'm referencing this stack overflow: <a href="https://stackoverflow.com/questions/4448340/postgresql-duplicate-key-violates-unique-constraint">postgresql duplicate key violates unique constraint</a></p>
  
  <p>But the post is 9 years old and the solution only checks if the primary key's max is greater than the next value of the sequence (which it isn't in my case).</p>