Re: Create or replace row in table

From: Mladen Gogala <mladen(dot)gogala(at)vmsinfo(dot)com>
To: Charles Holleran <scorpdaddy(at)hotmail(dot)com>
Cc: "pgsql-novice(at)postgresql(dot)org" <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Create or replace row in table
Date: 2010-09-02 03:53:52
Message-ID: 4C7F1FD0.2040507@vmsinfo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Charles Holleran wrote:
> Please pardon the total nubie question.
>
> There is a nice syntax for functions, "CREATE OR REPLACE FUNCTION xyz ..."
>
> What is the best syntax to create or replace a row in a table?
>
> Specifically: Update row in table t if row exists in table t else insert row in table t with source rows from temporary table s of same type as t.

INSERT or UPDATE should do the trick, especially when combined with
plpgsql, exceptions and basic error handling. You should be able to find
the relevant material here:
http://developer.postgresql.org/pgdocs/postgres/plpgsql-control-structures.html
and here:
http://developer.postgresql.org/pgdocs/postgres/errcodes-appendix.html

--
Mladen Gogala
Sr. Oracle DBA
1500 Broadway
New York, NY 10036
(212) 329-5251
www.vmsinfo.com

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message A B 2010-09-02 05:50:13 operator @> does not work with box.
Previous Message Charles Holleran 2010-09-02 01:37:44 Create or replace row in table