Re: update only if single row

Поиск
Список
Период
Сортировка
От Moray McConnachie
Тема Re: update only if single row
Дата
Msg-id 006001bfa06d$d45f5480$760e01a3@oucs.ox.ac.uk
обсуждение исходный текст
Ответ на update only if single row  (Frank Bax <fbax@execulink.com>)
Список pgsql-sql
> 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

If you have some kind of id field in the table, you can do it like this, or
you can use the oids, but I don't know how to write that :->
I'm not quite sure that the aliasing works properly in this query either -
does the EXISTS clause pick up the a alias?

UPDATE contact a SET a.bounce=1 WHERE a.email ~* 'rvro' AND NOT EXISTS
(SELECT id FROM contact b WHERE b.email ~*'rvro' AND a.id !=b.id);

Yours,
Moray




В списке pgsql-sql по дате отправления:

Предыдущее
От: "Moray McConnachie"
Дата:
Сообщение: Re: update only if single row
Следующее
От: "tjk@tksoft.com"
Дата:
Сообщение: Re: update only if single row