RE: INSERT [IGNORE] INTO TABLE

From: "Edmar Wiggers" <edmar(at)brasmap(dot)com>
To: "Petr Jezek" <jez20um(at)axpsu(dot)fpf(dot)slu(dot)cz>
Cc: <pgsql-sql(at)postgresql(dot)org>
Subject: RE: INSERT [IGNORE] INTO TABLE
Date: 2000-10-31 17:19:07
Message-ID: NEBBIAKDCDHFGJMLHCKIEENACAAA.edmar@brasmap.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message K Parker 2000-10-31 19:42:22 RE: INSERT [IGNORE] INTO TABLE
Previous Message Petr Jezek 2000-10-31 17:04:24 RE: INSERT [IGNORE] INTO TABLE