Обсуждение: Create or replace row in table

Поиск
Список
Период
Сортировка

Create or replace row in table

От
"Charles Holleran "
Дата:
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
tables of same type as t.  




Re: Create or replace row in table

От
Mladen Gogala
Дата:
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
temporarytable 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