3 ms·
So if there is a way to do UPSERT what is the problem? Are people just complaining about the lack of syntactic sugar?
by epo 13y ago
So if there is a way to do UPSERT what is the problem? Are people just complaining about the lack of syntactic sugar?
- masklinn 13y ago> what is the problem? Quoting ocharles: > susceptible to race conditions, which is why many of us want true UPSERT semantics The snippet provided in the postgres doc is the current best, but it's still has a number of flaws: > This coding assumes the unique_violation error is caused by the INSERT, and not by, say, an INSERT in a trigger function on the table. It might also misbehave if there is more than one unique index on the table, since it will retry the operation regardless of which index caused the error. More safety could be had by using the features discussed next to check that the trapped error was the one expected.