Re: update only if single row

From: "tjk(at)tksoft(dot)com" <tjk(at)tksoft(dot)com>
To: kl(at)84105(dot)aanet(dot)ru
Cc: pgsql-sql(at)postgreSQL(dot)org
Subject: Re: update only if single row
Date: 2000-04-07 09:39:00
Message-ID: 200004070939.CAA25714@uno.tksoft.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Excellent solution.

You can use oid as the unique attribute.

UPDATE contact SET bounce = 1 WHERE email ~* 'rvro' AND email NOT IN
(SELECT c1.email FROM contact c1, contact c2
WHERE c1.oid != c2.oid AND c1.email = c2.email);

Troy

>
> 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(at)84105(dot)aanet(dot)ru
>
>
>

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Allan Kelly 2000-04-07 10:34:01 duplicates
Previous Message Moray McConnachie 2000-04-07 09:36:52 Maxima per row