Received: from ibi.metrocom.ru (ibi.metrocom.ru [195.5.154.130]) by hub.org (8.9.3/8.9.3) with ESMTP id DAA01213 for ; Fri, 7 Apr 2000 03:28:42 -0400 (EDT) (envelope-from kl@84105.aanet.ru) Received: from 192.168.11.101 (ip-523.fixed.cl.spb.ru [212.46.199.9]) by ibi.metrocom.ru (8.9.3/8.9.3/IBI) with SMTP id LAA26548 for ; Fri, 7 Apr 2000 11:28:39 +0400 (envelope-from kl@84105.aanet.ru) Date: Fri, 7 Apr 2000 11:28:27 +0400 From: "Leonid P. Klemjatsionok" X-Mailer: The Bat! (v1.039) S/N 4F39C051 Reply-To: "Leonid P. Klemjatsionok" Message-ID: <14478.000407@84105.aanet.ru> To: pgsql-sql@postgreSQL.org Subject: Re: update only if single row References: <3.0.6.32.20000406132216.008a8420@execulink.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Archive-Number: 200004/59 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