Conceptually, a MERGE statement is just a long string of INSERTs and
UPDATEs in the same transaction and I think we should treat it as
such.

I've just got one question about this. Everyone seems to be saying that "try to insert and if that fails update" is the same as "try to insert and if that fails delete and then insert".

What about the following scenario:

mytable
------------
id  serial primary key,
a  int4,
b  int4,
data text

I've got an id field on every table because it simplifies a lot of things (such as slony configuration for example) But I've also got a unique key on (a, b) and if I was to do a merge I would most likely do it in (a, b) not id.

If merge does a delete insert then it creates new values for the id columns which could cause me problems. Basically any default fields are going to change or for that matter any fields not specified would be reinitialized whereas an update would leave them in place.

It seems to me that "try to update and if that fails insert" seems to be the best approach for not messing with existing data. I guess "try to insert and if that fails update" gets you the same effect.

- Rick Gigger

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

              http://archives.postgresql.org

Reply via email to