From: Leonid P. Klemjatsionok <kl@84105.aanet.ru>
To: pgsql-sql@postgreSQL.org
Subject: Re: update only if single row
Date: Fri, 7 Apr 2000 11:28:27 +0400
Message-ID: <14478.000407@84105.aanet.ru> (raw)
References: <3.0.6.32.20000406132216.008a8420@execulink.com>
Hi
FB> select * from contact where email ~* 'rvro';
FB> if I get a single row in the result then I enter:
FB> update contact set bounce=1 where email ~* 'rvro';
FB> Can I combine this into a single SQL statement with the following
FB> requirements:
FB> 1) the update is only performed if a single row is selected
FB> 2) I only enter the selection string ('rvro' in this case) once in the
FB> command?
Assume that pk is PRIMARY KEY (or UNIQUE attribute) of relation contact.
UPDATE contact SET bounce = 1 WHERE email ~* 'rvro' AND NOT email IN
(SELECT c1.email FROM contact c1, contact c2
WHERE c1.pk != c2.pk AND c1.email = c2.email);
LPK Station mailto:kl@84105.aanet.ru
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: kl@84105.aanet.ru
Subject: Re: update only if single row
In-Reply-To: <14478.000407@84105.aanet.ru>
References: <3.0.6.32.20000406132216.008a8420@execulink.com> <14478.000407@84105.aanet.ru>
* 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