From: | Nabil Sayegh <postgresql(at)e-trolley(dot)de> |
---|---|
To: | brew(at)theMode(dot)com |
Cc: | "'PGSQL-NOVICE(at)postgresql(dot)org'" <PGSQL-NOVICE(at)postgresql(dot)org>, jcboget(at)yahoo(dot)com |
Subject: | Re: Replace into... |
Date: | 2003-07-06 11:43:53 |
Message-ID: | 1057491833.2084.2.camel@billy |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
Am Son, 2003-07-06 um 02.22 schrieb brew(at)theMode(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2003-07-06 15:19:25 | Re: [PERFORM] Extreme high load averages |
Previous Message | Shridhar Daithankar | 2003-07-06 10:34:48 | Re: Extreme high load averages |