Re: [GENERAL] Function with limit and offset - PostgreSQL 9.3

Поиск
Список
Период
Сортировка
От John R Pierce
Тема Re: [GENERAL] Function with limit and offset - PostgreSQL 9.3
Дата
Msg-id dc8309c4-08c0-59b1-6d80-0965ba1fe4f0@hogranch.com
обсуждение исходный текст
Ответ на Re: [GENERAL] Function with limit and offset - PostgreSQL 9.3  (marcinha rocha <marciaestefanidarocha@hotmail.com>)
Список pgsql-general
On 6/8/2017 6:36 PM, marcinha rocha wrote:
UPDATE tablea a SET migrated = yes WHERE a.id = row.id;
On my original select, the row will have migrated = false. Maybe All I need to put is a limit 2000 and the query will do the rest?

 SELECT does not return data in any determinate order unless you use an ORDER BY....   so LIMIT 2000 would return some 2000 elements, not neccessarily the 'first' 2000 elements unless you somehow order them by however you feel 'first' is defined.


    WITH ids AS (INSERT INTO tableb (id) SELECT id FROM tablea WHERE migrated=FALSE ORDER BY id LIMIT 2000 RETURNING id)
        UPDATE tablea a SET a.migrated=TRUE WHERE a.id = ids.id RETURNING COUNT(a.id);



I'm not 100% sure you can do UPDATE .... RETURNING COUNT(...), worse case the UPDATE RETURNING would be a subquery of a SELECT COUNT()...


-- 
john r pierce, recycling bits in santa cruz

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

Предыдущее
От: "David G. Johnston"
Дата:
Сообщение: Re: [GENERAL] Function with limit and offset - PostgreSQL 9.3
Следующее
От: Ken Tanzer
Дата:
Сообщение: [GENERAL] Limiting DB access by role after initial connection?