160 shaares
PostgreSQL conditional upserts
So in order to do an "upsert" we use an INSERT command with a CONFLICT statement. Then if we need to do some conditional setting in the case of existing data then we can use the "temp table" EXCLUDED that PostgreSQL provide to us. They have a nice example how to use that in their docs and here's mine example: