Forum OpenACS Development: Response to insert or update a row in postgres

Collapse
Posted by Don Baccus on
There are some tricky concurrency issues here ... if two threads try to update at the same time and there are no rows, they'll both try to insert and either  one will fail (if you have a sufficiently tight unique constraint) or you'll get duplicate rows.  The first alternative's the best so double-check those key definitions on apm_parameter_values!

Such errors are unlikely in your particular scenario so you could probably just catch and report the error and ask the user to try again, or have the code try again.

You could implement a "before" insert trigger, check for the existing row, and update instead from within the trigger function.