From: tjk@tksoft.com <tjk@tksoft.com>
To: kl@84105.aanet.ru
Cc: pgsql-sql@postgreSQL.org
Subject: Re: update only if single row
Date: Fri, 7 Apr 2000 02:39:00 -0700 (PDT)
Message-ID: <200004070939.CAA25714@uno.tksoft.com> (raw)
In-Reply-To: <14478.000407@84105.aanet.ru>
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@84105.aanet.ru
>
>
>
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: tjk@tksoft.com, kl@84105.aanet.ru
Subject: Re: update only if single row
In-Reply-To: <200004070939.CAA25714@uno.tksoft.com>
References: <14478.000407@84105.aanet.ru> <200004070939.CAA25714@uno.tksoft.com>
* 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