Re: Update on Insert

From: Andreas Kretschmer <akretschmer(at)spamfence(dot)net>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Update on Insert
Date: 2009-11-16 20:53:42
Message-ID: mnq8t6-4be.ln1@news.a-kretschmer.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

SebiF <sfeher(at)gmail(dot)com> wrote:
> Hi Everyone,
>
> Given a table "Items" with a PK "item1" and "Qty" - a numeric column
> I'd like to define a way in Postgres to insert when item11 doesn't
> exist already in "Items" and update the Qty by adding the new quantity
> to the existent when the item11 exists. What is a good approach and
> where should I be looking for details. Thanks.

21:53 < akretschmer> ??upsert
21:53 < rtfm_please> For information about upsert
21:53 < rtfm_please> see http://www.postgresql.org/docs/current/static/plpgsql-control-structures.html#PLPGSQL-UPSERT-EXAMPLE

Read that.

Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect. (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly." (unknown)
Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°

In response to

Browse pgsql-general by date

  From Date Subject
Next Message manitou-sig 2009-11-16 21:11:47 Re: passing parameters to multiple statements
Previous Message John DeSoi 2009-11-16 20:26:54 Re: Need full search text on a shared hosting web site using 8.1.x

Browse pgsql-hackers by date

  From Date Subject
Next Message Greg Smith 2009-11-16 20:57:10 Re: write ahead logging in standby (streaming replication)
Previous Message Peter Eisentraut 2009-11-16 20:37:07 Re: UTF8 with BOM support in psql