Re: Replace into... - Mailing list pgsql-novice

From Nabil Sayegh
Subject Re: Replace into...
Date
Msg-id 1057491833.2084.2.camel@billy
Whole thread Raw
In response to Re: Replace into...  (brew@theMode.com)
List pgsql-novice
Am Son, 2003-07-06 um 02.22 schrieb brew@theMode.com:
> Hi Chris.......
>
> > The problem, though, is that I need this type of functionality... To
> > INSERT or UPDATE depending on whether or not the record is already
> > there.  I've spent the last several hours trying to figure out how I can
> > set up a trigger to do this.
>
> Don't know about a trigger, but the way I do this is do a SELECT, if no
> rows are returned I do an INSERT, if rows are returned I do an UPDATE.
>
> Somebody else probably has a more clever way to do it though......

I would do this unconditionally.
UPDATE ... FROM ... WHERE EXISTS (SELECT ...)
INSERT INTO ... WHERE NOT EXISTS (SELECT ...)

That are still 2 queries, but better than playing around with triggers.

HTH
--
 e-Trolley Sayegh & John, Nabil Sayegh
 Tel.: 0700 etrolley /// 0700 38765539
 Fax.: +49 69 8299381-8
 PGP : http://www.e-trolley.de


pgsql-novice by date:

Previous
From: Martin Foster
Date:
Subject: Re: [PERFORM] Extreme high load averages
Next
From: Tom Lane
Date:
Subject: Re: [PERFORM] Extreme high load averages