You could use a custom database function, but that will require someone manual work trough.
http://koo.fi/blog/2014/01/04/upsert-methods-for-postgresql/

For PostgreSQL 9.1 you can use a writable CTE.
http://stackoverflow.com/questions/1109061/insert-on-duplicate-update-in-postgresql/8702291#8702291

I wonder if checking if the id exists is faster then deleting it and then directly inserting it.
Knowing that id is unique (indexed) it should not be to slow.