Re: Transaction en erreur sur CLOSE ou INSERT

From: Stephane Bortzmeyer <bortzmeyer(at)nic(dot)fr>
To: philippe(dot)beaudoin(at)bull(dot)net
Cc: pgsql-fr-generale(at)postgresql(dot)org
Subject: Re: Transaction en erreur sur CLOSE ou INSERT
Date: 2009-01-12 10:26:22
Message-ID: 20090112102622.GA15178@nic.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-fr-generale

On Sat, Jan 10, 2009 at 10:41:57AM +0100,
philippe(dot)beaudoin(at)bull(dot)net <philippe(dot)beaudoin(at)bull(dot)net> wrote
a message of 68 lines which said:

> 2) Détection de doublon sur INSERT

N'est-ce pas ce qu'on appelle couramment un UPSERT
<http://en.wikipedia.org/wiki/Upsert> ? Si oui, outre la solution du
UPDATE-if-rowcount-0-INSERT, il y a celle du
SELECT-if-not-found-INSERT-else-UPDATE.

Dans le deuxième cas, il faut évidemment tout emballer dans une
transaction au niveau SERIALIZABLE.

En attendant que quelqu'un code <http://wiki.postgresql.org/wiki/Todo> :

Add SQL-standard MERGE/REPLACE/UPSERT command

MERGE is typically used to merge two tables. REPLACE or UPSERT command does UPDATE, or on failure, INSERT. This is similar to UPDATE, then for unmatched rows, INSERT. Whether concurrent access allows modifications which could cause row loss is implementation independent. To implement this cleanly requires that the table have a unique index so duplicate checking can be easily performed. It is possible to do it without a unique index if we require the user to LOCK the table before the MERGE.

* someone working to add merge?
* MERGE vs REPLACE
* MERGE SQL Statement
* MERGE Specification
* Internal design of MERGE, with Rules

In response to

Responses

Browse pgsql-fr-generale by date

  From Date Subject
Next Message Marc Cousin 2009-01-12 10:40:16 Re: Transaction en erreur sur CLOSE ou INSERT
Previous Message Marc Cousin 2009-01-12 09:07:21 Re: Réf. : Re: [pgsql-fr-generale] Transaction en erreur sur CLOSE ou INSERT