From: David Welton <davidw@gate.cks.com>
To: pgsql-sql@postgresql.org
Subject: insert/update
Date: Mon, 12 Oct 1998 13:23:25 -0700
Message-ID: <19981012132325.N31505@gate.cks.com> (raw)
[ please CC replies to me ]
I've been reading my sql, looking through the postgres docs, but still
haven't managed to find a clean way to do what I want, to wit:
$foo{"bar"} ++ ; # expressed in perl..
if $foo{"bar"} does not exist, it gets created and set to 1. If it
does exist, it gets increased by one. In SQL, it seems as if there is
no way to do this in one operation, and without using some sort of
language -
if (foo exists in table.row)
update table set row2 = row2 + 1 where row = 'foo';
else
insert into table values ('foo', 1);
This is certainly not elegant, IMHO, and would like to find a way of
doing it in just sql - is this possible? I would like this to be
portable to other sql implementations, if at all possible.
Thanks,
--
David Welton http://www.efn.org/~davidw
Debian GNU/Linux - www.debian.org
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: davidw@gate.cks.com
Subject: Re: insert/update
In-Reply-To: <19981012132325.N31505@gate.cks.com>
References: <19981012132325.N31505@gate.cks.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