mirror of
https://github.com/postgres/postgres.git
synced 2025-08-28 18:48:04 +03:00
Doc: show how to get the equivalent of LIMIT for UPDATE/DELETE.
Add examples showing use of a CTE and a self-join to perform partial UPDATEs and DELETEs. Corey Huinker, reviewed by Laurenz Albe Discussion: https://postgr.es/m/CADkLM=caNEQsUwPWnfi2jR4ix99E0EJM_3jtcE-YjnEQC7Rssw@mail.gmail.com
This commit is contained in:
@@ -260,12 +260,32 @@ DELETE FROM tasks WHERE status = 'DONE' RETURNING *;
|
||||
</programlisting>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
<para>
|
||||
Delete the row of <structname>tasks</structname> on which the cursor
|
||||
<literal>c_tasks</literal> is currently positioned:
|
||||
<programlisting>
|
||||
DELETE FROM tasks WHERE CURRENT OF c_tasks;
|
||||
</programlisting></para>
|
||||
</programlisting>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
While there is no <literal>LIMIT</literal> clause
|
||||
for <command>DELETE</command>, it is possible to get a similar effect
|
||||
using the same method described in <link linkend="update-limit">the
|
||||
documentation of <command>UPDATE</command></link>:
|
||||
<programlisting>
|
||||
WITH delete_batch AS (
|
||||
SELECT l.ctid FROM user_logs AS l
|
||||
WHERE l.status = 'archived'
|
||||
ORDER BY l.creation_date
|
||||
FOR UPDATE
|
||||
LIMIT 10000
|
||||
)
|
||||
DELETE FROM user_logs AS dl
|
||||
USING delete_batch AS del
|
||||
WHERE dl.ctid = del.ctid;
|
||||
</programlisting>
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1>
|
||||
|
Reference in New Issue
Block a user