Re: update only if single row

Поиск
Список
Период
Сортировка
От tjk@tksoft.com
Тема Re: update only if single row
Дата
Msg-id 200004062018.NAA22377@uno.tksoft.com
обсуждение исходный текст
Ответ на update only if single row  (Frank Bax <fbax@execulink.com>)
Список 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 по дате отправления:

Предыдущее
От: Michael Fork
Дата:
Сообщение: Re: Datetime as a time_t?
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Datetime as a time_t?