From: | "Harald Armin Massa" <haraldarminmassa(at)gmail(dot)com> |
---|---|
To: | Vittorio <vdemart1(at)tin(dot)it> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Updating & inserting in one shot! |
Date: | 2006-04-10 08:55:44 |
Message-ID: | 7be3f35d0604100155x52abd590oc45b94899b56851c@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
nearly ready to use
replace (int4, text, "timestamp") with your fieldtypes; its convention:
first param is primary key
replace
update bcachekredbetr set
betreuer=$2, letztespeicherung=$3
where id_p=$1;
with the appropriate update (where clause -> references primary key)
CREATE OR REPLACE FUNCTION uoibcachekredbetr(int4, text, "timestamp")
RETURNS int4 AS
$BODY$
DECLARE
result int4;
BEGIN
update bcachekredbetr set
betreuer=$2, letztespeicherung=$3
where id_p=$1;
IF FOUND THEN
result:=-1;
else
insert into bcachekredbetr (
id_p, betreuer, letztespeicherung
)
values ($1, $2, $3);
result:=$1;
END IF;
RETURN result;
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;
hth,
Harald
On 4/10/06, Vittorio <vdemart1(at)tin(dot)it> wrote:
>
> In my Postgresql 8.06 db I have a table in which the key fields are a
> date and a code.
>
> Now I need to load data from a text file (or a
> temporary table) that either should update OR should be insert-ed into
> that table.
>
> Is there any ready-to-use, contributed function allowing
> this 1-shot update-insert into a table?
>
> Ciao
> Vittorio
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: Don't 'kill -9' the postmaster
>
--
GHUM Harald Massa
persuadere et programmare
Harald Armin Massa
Reinsburgstraße 202b
70197 Stuttgart
0173/9409607
-
PostgreSQL - supported by a community that does not put you on hold
From | Date | Subject | |
---|---|---|---|
Next Message | Aaron Bingham | 2006-04-10 09:04:53 | Re: how to document database |
Previous Message | Richard Huxton | 2006-04-10 08:55:28 | Re: Load testing across 2 machines |