Re: How to update rows from a cursor in PostgreSQL

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: How to update rows from a cursor in PostgreSQL
Дата
Msg-id 2274.1045882562@sss.pgh.pa.us
обсуждение исходный текст
Ответ на How to update rows from a cursor in PostgreSQL  (Ruben <ruben12@superguai.com>)
Ответы Re: How to update rows from a cursor in PostgreSQL  (Emmanuel Charpentier <charpent@bacbuc.dyndns.org>)
Re: How to update rows from a cursor in PostgreSQL  (Bruce Momjian <pgman@candle.pha.pa.us>)
Список pgsql-general
Ruben <ruben12@superguai.com> writes:
> Since "FOR UPDATE" cursors are not supported in PostgreSQL, can I update
> the current row of table t1?

The usual hack for this is to select the table's "ctid" system column as
part of the cursor output, and then say

    UPDATE t1 SET ... WHERE ctid = 'what-you-got-from-the-cursor';

This is quite fast because the ctid is essentially a physical locator.
Note however that it will fail (do nothing) if someone else has already
updated the same row since your transaction started.  This may or may
not be what you want.  I think ODBC has some hack to find the ctid of
the latest version of the row.

            regards, tom lane

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Views + Rules + Triggers + 7.3.2 = Upgrade Problems (was: Re: REWRITE_INVOKE_MAX and "query may contain cycles" )
Следующее
От: Tom Lane
Дата:
Сообщение: Re: regexp question