Re: update only if single row - Mailing list pgsql-sql

From Leonid P. Klemjatsionok
Subject Re: update only if single row
Date
Msg-id 14478.000407@84105.aanet.ru
Whole thread Raw
In response to update only if single row  (Frank Bax <fbax@execulink.com>)
Responses Re: update only if single row  ("tjk@tksoft.com" <tjk@tksoft.com>)
List pgsql-sql
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




pgsql-sql by date:

Previous
From: Frank Bax
Date:
Subject: Re: Datetime as a time_t?
Next
From: "Moray McConnachie"
Date:
Subject: Re: update only if single row