Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
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

pgsql-novice by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group