doc: warn about the use of "ctid" queries beyond the examples master github/master
authorBruce Momjian <bruce@momjian.us>
Fri, 26 Dec 2025 22:34:17 +0000 (17:34 -0500)
committerBruce Momjian <bruce@momjian.us>
Fri, 26 Dec 2025 22:34:17 +0000 (17:34 -0500)
Also be more assertive that "ctid" should not be used for long-term
storage.

Reported-by: Bernice Southey
Discussion: https://postgr.es/m/CAEDh4nyn5swFYuSfcnGAbpQrKOc47Hh_ZyKVSPYJcu2P=51Luw@mail.gmail.com

Backpatch-through: 17

doc/src/sgml/ddl.sgml
doc/src/sgml/ref/delete.sgml
doc/src/sgml/ref/update.sgml

index cea28c00f8a85f90c71d67834627fa72a2e0691f..9070aaa5a7cd85b7a17f0a4fde7d3ad6b03d8e58 100644 (file)
@@ -1558,7 +1558,7 @@ CREATE TABLE circles (
       locate the row version very quickly, a row's
       <structfield>ctid</structfield> will change if it is
       updated or moved by <command>VACUUM FULL</command>.  Therefore
-      <structfield>ctid</structfield> is useless as a long-term row
+      <structfield>ctid</structfield> should not be used as a row
       identifier.  A primary key should be used to identify logical rows.
      </para>
     </listitem>
index 5b52f77e28f43445d9aea8e41b30db113e62972c..b9367f2b23cfd8c205d000a684a427af7d31f531 100644 (file)
@@ -323,6 +323,9 @@ DELETE FROM user_logs AS dl
   USING delete_batch AS del
   WHERE dl.ctid = del.ctid;
 </programlisting>
+   This use of <structfield>ctid</structfield> is only safe because
+   the query is repeatedly run, avoiding the problem of changed
+   <structfield>ctid</structfield>s.
   </para>
  </refsect1>
 
index 40cca06394636b1db20081756bcd34c08708ba56..b523766abe303a5a0d54ecb6644f75fd7945d36a 100644 (file)
@@ -503,6 +503,9 @@ UPDATE work_item SET status = 'failed'
   WHERE work_item.ctid = emr.ctid;
 </programlisting>
    This command will need to be repeated until no rows remain to be updated.
+   (This use of <structfield>ctid</structfield> is only safe because
+   the query is repeatedly run, avoiding the problem of changed
+   <structfield>ctid</structfield>s.)
    Use of an <literal>ORDER BY</literal> clause allows the command to
    prioritize which rows will be updated; it can also prevent deadlock
    with other update operations if they use the same ordering.