RE: INSERT [IGNORE] INTO TABLE - Mailing list pgsql-sql

From Edmar Wiggers
Subject RE: INSERT [IGNORE] INTO TABLE
Date
Msg-id NEBBIAKDCDHFGJMLHCKIEENACAAA.edmar@brasmap.com
Whole thread Raw
In response to RE: INSERT [IGNORE] INTO TABLE  (Petr Jezek <jez20um@axpsu.fpf.slu.cz>)
List pgsql-sql
> > Check existence and then insert or update. If you want, I guess
> you could
> > wrap that inside a stored procedure.
> >
>     Well, that's a good idea :-) but I'm not sure about how to create
>     such procedure. I would appreciate Your help.

Quite frankly, I'm not sure either. I'm just starting with PostgreSQL, what
I really know is Oracle. I believe it would be something like

...
[declare routine, with one argument per record field]
...
if exists(select 1 from table_name where [field_key] = [arg_key]) then update table_name  set field1 = arg1,...,fieldn
=argn  where field_key = arg_key;
 
else insert into table_name (field1,...,fieldn) values (arg1,...,argn);
end if;
...

The syntax is probably off, but that's the idea. I used that several times
on oracle.



pgsql-sql by date:

Previous
From: Petr Jezek
Date:
Subject: RE: INSERT [IGNORE] INTO TABLE
Next
From: Najm Hashmi
Date:
Subject: Re: INSERT [IGNORE] INTO TABLE