I have a table with column Id,column1,column2.
I wants to make sure only one record exists with column1 and column2 value (column1+column2 is unique).
If there is an already record exists with column1=v1 and column2=v2 then I wants to select the Id or insert a record with column1=v1 and column2=v2. I do not want to first select and then check and then insert since there could be a chance that 2 request came with same time with same values, both should be success but only one record should get created in DB and after that i want the Id in both request.
How to do this with single SQL ? Or is there any other better approach ?
Database : Postgres