From: Andreas <maps.on@gmx.net>
To: pgsql-sql@postgresql.org
Subject: Howto "insert or update" ?
Date: Tue, 23 Nov 2010 04:44:48 +0100
Message-ID: <4CEB38B0.8050901@gmx.net> (raw)
Hi,
is there an elegant way to tell PG :
a) Hey PG, look here are e.g. 3 values A, B, c for tableX
b) please check if there is a row matching A and B as key in tableX
c) if such a row exists, execute an UPDATE on column c else INSERT a
new row.
Currently I have a trigger function that should store a value in tableX
whenever a certain column in tableY gets changed.
I do it with:
a) delete from tableX where key = ( A, B ) ( regardless if there is one )
b) insert into tableX
This seems not very efficient though it works.
Is there a better way?
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 using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: maps.on@gmx.net
Subject: Re: Howto "insert or update" ?
In-Reply-To: <4CEB38B0.8050901@gmx.net>
* 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