From: Edmar Wiggers <edmar@brasmap.com>
To: Petr Jezek <jez20um@axpsu.fpf.slu.cz>
Cc: pgsql-sql@postgresql.org
Subject: RE: INSERT [IGNORE] INTO TABLE
Date: Tue, 31 Oct 2000 15:19:07 -0200
Message-ID: <NEBBIAKDCDHFGJMLHCKIEENACAAA.edmar@brasmap.com> (raw)
In-Reply-To: <Pine.LNX.4.10.10010311741080.30822-100000@axpsu.fpf.slu.cz>
> > 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.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: edmar@brasmap.com, jez20um@axpsu.fpf.slu.cz
Subject: Re: INSERT [IGNORE] INTO TABLE
In-Reply-To: <NEBBIAKDCDHFGJMLHCKIEENACAAA.edmar@brasmap.com>
References: <Pine.LNX.4.10.10010311741080.30822-100000@axpsu.fpf.slu.cz> <NEBBIAKDCDHFGJMLHCKIEENACAAA.edmar@brasmap.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox