pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Moray McConnachie <moray.mcconnachie@computing-services.oxford.ac.uk>
To: Leonid P. Klemjatsionok <kl@84105.aanet.ru>
To: pgsql-sql@postgresql.org
Subject: Re: update only if single row
Date: Fri, 7 Apr 2000 09:39:29 +0100
Message-ID: <004001bfa06c$ca5c9340$760e01a3@oucs.ox.ac.uk> (raw)
References: <3.0.6.32.20000406132216.008a8420@execulink.com>
	<14478.000407@84105.aanet.ru>

----- Original Message -----
From: "Leonid P. Klemjatsionok" <kl@84105.aanet.ru>
To: <pgsql-sql@postgreSQL.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.McConnachie@computing-services.oxford.ac.uk




view thread (8+ messages)  latest in thread

Message-ID: <004001bfa06c$ca5c9340$760e01a3@oucs.ox.ac.uk>
Permalink:  ../004001bfa06c$ca5c9340$760e01a3@oucs.ox.ac.uk/
Also on:    postgresql.org/message-id/004001bfa06c$ca5c9340$760e01a3@oucs.ox.ac.uk

 · 

reply

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: moray.mcconnachie@computing-services.oxford.ac.uk, kl@84105.aanet.ru
  Subject: Re: update only if single row
  In-Reply-To: <004001bfa06c$ca5c9340$760e01a3@oucs.ox.ac.uk>
  References: <3.0.6.32.20000406132216.008a8420@execulink.com> <14478.000407@84105.aanet.ru> <004001bfa06c$ca5c9340$760e01a3@oucs.ox.ac.uk>

* 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