0

I have a situation, where new patients can be created through multiple portals simultaneously.

I am working in PostgreSQL DB.

Thanks in Advance. VD.

Currently we are considering MAX(id) and incrementing by 1. However, if multiple users login simultaneously then both gets same MAX(ID), which is creating duplicate id issue.

Can someone suggest what's way to generate new id in this scenario?

  • 1
    Use an auto increment column, see the duplicate link. – Tim Biegeleisen Aug 24 '23 at 13:57
  • Yes, MAX(id)+1 is a virtual guarantee you will get duplicates. Depending on you version redefine `id` to `generated always as identity` (*v10 and later*) or as serial/bigserial (*v8 and later*). See documentation [here](https://www.postgresql.org/docs/current/sql-createtable.html) and [here](https://www.postgresql.org/docs/9.6/sql-createtable.html) and phere](https://www.postgresql.org/docs/8.0/sql-createtable.html). – Belayer Aug 24 '23 at 16:39

0 Answers0