If you have a table with an unique key field, want to insert new values but you don’t know if the value may already be in the table, you can use the following query:
| |
This does avoid unique key violation errors in a way, that no insert will happen if the value is already in the table.
I would like to thank depesz from #postgresql for the idea.