Re: INSERT OR UPDATE

From: Tony Wasson <ajwasson(at)gmail(dot)com>
To: Julian Scarfe <julian(at)avbrief(dot)com>
Cc: PostgreSQL General <pgsql-general(at)postgresql(dot)org>
Subject: Re: INSERT OR UPDATE
Date: 2006-01-03 06:02:56
Message-ID: 6d8daee30601022202g42666269ue144b28dab28ff4@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 1/2/06, Julian Scarfe <julian(at)avbrief(dot)com> wrote:
> I'm keeping config information for an application in a series of related
> tables. I'd like a command that INSERTs data if it's new, or UPDATEs it if
> the key is duplicated.

A MERGE trigger will do exactly what you are asking for.

http://archives.postgresql.org/pgsql-sql/2004-05/msg00135.php

Send all your data as INSERTS.
The trigger will run a function to see if the row exists.
If the row exists -> rewrite it as it as an UPDATE
If the row does not exist -> leave the INSERT alone

Tony

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Andrew - Supernews 2006-01-03 06:32:04 Re: INSERT OR UPDATE
Previous Message Lucky Leavell 2006-01-03 04:30:38 Re: Ident authentication failed