Re: update only if single row

From: "Moray McConnachie" <moray(dot)mcconnachie(at)computing-services(dot)oxford(dot)ac(dot)uk>
To: "Leonid P(dot) Klemjatsionok" <kl(at)84105(dot)aanet(dot)ru>, <pgsql-sql(at)postgresql(dot)org>
Subject: Re: update only if single row
Date: 2000-04-07 08:39:29
Message-ID: 004001bfa06c$ca5c9340$760e01a3@oucs.ox.ac.uk
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-sql

----- Original Message -----
From: "Leonid P. Klemjatsionok" <kl(at)84105(dot)aanet(dot)ru>
To: <pgsql-sql(at)postgreSQL(dot)org>
Sent: Friday, April 07, 2000 8:28 AM
Subject: Re: [SQL] update only if single row

> 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);

Surely this is not the same thing at all? This potentially updates several
rows, where there are several non-identical email addresses which all
contain rvro. The original two querys only update the row where there is
only one email address which contains rvro.

Yours,
Moray

----------------------------------------------------------------
Moray(dot)McConnachie(at)computing-services(dot)oxford(dot)ac(dot)uk

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Moray McConnachie 2000-04-07 08:46:56 Re: update only if single row
Previous Message Leonid P. Klemjatsionok 2000-04-07 07:28:27 Re: update only if single row