Re: update only if single row

From: "tjk(at)tksoft(dot)com" <tjk(at)tksoft(dot)com>
To: fbax(at)execulink(dot)com (Frank Bax)
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: update only if single row
Date: 2000-04-06 20:18:40
Message-ID: 200004062018.NAA22377@uno.tksoft.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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
>

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2000-04-06 20:54:06 Re: Datetime as a time_t?
Previous Message Michael Fork 2000-04-06 19:46:50 Re: Datetime as a time_t?