From: | "Guy Rouillier" <guyr(at)masergy(dot)com> |
---|---|
To: | "PostgreSQL General" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: INSERT OR UPDATE |
Date: | 2006-01-03 03:06:01 |
Message-ID: | CC1CF380F4D70844B01D45982E671B239E8DD9@mtxexch01.add0.masergy.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Julian Scarfe 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.
Write a stored procedure called something like InsertUpdateConfigData.
Pick the operation that you think is most likely to occur more often
(the insert or update). Code that as the initial statement. Then
create an exception block, and in that exception block catch the error
that would result from the initial statement being executed in the case
where the other one should have been; then execute that other statement.
There is no magic database-provided SQL statement that says "try an
insert and if that fails then try an update." You have to do that
yourself.
--
Guy Rouillier
From | Date | Subject | |
---|---|---|---|
Next Message | Lucky Leavell | 2006-01-03 03:17:07 | Ident authentication failed |
Previous Message | Tony Wasson | 2006-01-02 22:45:13 | Re: using PG with Syslog |