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

From tjk@tksoft.com
Subject Re: update only if single row
Date
Msg-id 200004062018.NAA22377@uno.tksoft.com
Whole thread Raw
In response to update only if single row  (Frank Bax <fbax@execulink.com>)
List pgsql-sql
Frank,

The best I can come up with is using a temp table.
Something like:

select email into temp dummytable from contact where email ~* 'rvro' group by email having count(*) = 1;
update contact set bounce = 1 where email in (select email from dummytable);


It's still two queries. One use of your query, though.

Other than this, I would need to resort to a function.


Cheers,


Troy



>
> Here's the way I do it now:
>
> select * from contact where email ~* 'rvro';
> if I get a single row in the result then I enter:
> update contact set bounce=1 where  email ~* 'rvro';
>
> Can I combine this into a single SQL statement with the following
> requirements:
> 1) the update is only performed if a single row is selected
> 2) I only enter the selection string ('rvro' in this case) once in the
> command?
>
> Frank
>

pgsql-sql by date:

Previous
From: Michael Fork
Date:
Subject: Re: Datetime as a time_t?
Next
From: Tom Lane
Date:
Subject: Re: Datetime as a time_t?