I have a database table in PostgreSQL called "item" that have 3 columns
id: UUID
name: VARCHAR
type: VARCHAR
The "id" column is a primary key and there is no other constraint or index in this table.
My requirements are: if two rows have the same name, they should not have the same type which means the same type can not be attached to the same name more than once.
Here is my question:
How to insert a new row with maintaining my previous condition and taking into consideration the race condition that night happen with concurrent transactions?
I have already read about conditional insert (using WHERE NOT EXIST) but it has a caveat as mentioned here: https://stackoverflow.com/a/13342031/7972923