https://wiki.postgresql.org/wiki/UPSERT
Anonymous
Prototype before polishing. Get it working before you optimize it.