Re: Chunk Delete

Поиск
Список
Период
Сортировка
От Gregory Stark
Тема Re: Chunk Delete
Дата
Msg-id 87abpfwhxf.fsf@oxford.xeocode.com
обсуждение исходный текст
Ответ на Chunk Delete  ("Abraham, Danny" <danny_abraham@bmc.com>)
Ответы Re: Chunk Delete  (Csaba Nagy <nagy@ecircle-ag.com>)
Список pgsql-general
"Abraham, Danny" <danny_abraham@bmc.com> writes:

> Hi,
>
> I am wondering if I can do in PG Chunck Delete, like the Oracle example
> below.
>
> In Oracle we erase 50,000 records using the following:
>
> Delete <table name> where <condition> and ROWNUM < 50000;
>
> Do we have such a feature in PG?

You can still use a subquery even if you don't have a primary key. You use the
"ctid" which is Postgres's notion of the physical location of the record. You
do have to use another non-standard extension DELETE ... USING.


DELETE
  FROM atable AS x
 USING (SELECT ctid FROM atable LIMIT 50000) AS y
 WHERE x.ctid = y.ctid;


(The ctid can change when it's updated and even be reused by another record
but within a single query like this it's safe though it's possible the query
will delete fewer than 50000 records though if one of the records is updated
while the delete is running.)

You should note this will delete 50,000 arbitrary records. Not necessarily the
50,000 oldest ones or anything useful.

--
  Gregory Stark
  EnterpriseDB          http://www.enterprisedb.com
  Ask me about EnterpriseDB's Slony Replication support!

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

Предыдущее
От: Gregory Stark
Дата:
Сообщение: Re: Variable LIMIT and OFFSET in SELECTs
Следующее
От: Gregory Stark
Дата:
Сообщение: Re: Variable LIMIT and OFFSET in SELECTs