Re: Replace into...

Поиск
Список
Период
Сортировка
От Nabil Sayegh
Тема Re: Replace into...
Дата
Msg-id 1057491833.2084.2.camel@billy
обсуждение исходный текст
Ответ на Re: Replace into...  (brew@theMode.com)
Список 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 по дате отправления:

Предыдущее
От: Martin Foster
Дата:
Сообщение: Re: [PERFORM] Extreme high load averages
Следующее
От: Tom Lane
Дата:
Сообщение: Re: [PERFORM] Extreme high load averages