Skip to content

Commit 709ce29

Browse files
committed
doc: Add better description for rewrite functions in event triggers
There are two functions that can be used in event triggers to get more details about a rewrite happening on a relation. Both had a limited documentation: - pg_event_trigger_table_rewrite_reason() and pg_event_trigger_table_rewrite_oid() were not mentioned in the main event trigger section in the paragraph dedicated to the event table_rewrite. - pg_event_trigger_table_rewrite_reason() returns an integer which is a bitmap of the reasons why a rewrite happens. There was no explanation about the meaning of these values, forcing the reader to look at the code to find out that these are defined in event_trigger.h. While on it, let's add a comment in event_trigger.h where the AT_REWRITE_* are defined, telling to update the documentation when these values are changed. Backpatch down to 13 as a consequence of 1ad2333, where this area of the documentation has been heavily reworked. Author: Greg Sabino Mullane Discussion: https://postgr.es/m/CAKAnmmL+Z6j-C8dAx1tVrnBmZJu+BSoc68WSg3sR+CVNjBCqbw@mail.gmail.com Backpatch-through: 13
1 parent e5086b3 commit 709ce29

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

doc/src/sgml/event-trigger.sgml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@
9999
control statements are available to rewrite a table,
100100
like <literal>CLUSTER</literal> and <literal>VACUUM</literal>,
101101
the <literal>table_rewrite</literal> event is not triggered by them.
102+
To find the OID of the table that was rewritten, use the function
103+
<literal>pg_event_trigger_table_rewrite_oid()</literal> (see
104+
<xref linkend="functions-event-triggers"/>). To discover the reason(s)
105+
for the rewrite, use the function
106+
<literal>pg_event_trigger_table_rewrite_reason()</literal>.
102107
</para>
103108

104109
<para>

doc/src/sgml/func.sgml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31110,8 +31110,12 @@ CREATE EVENT TRIGGER test_event_trigger_for_drops
3111031110
<returnvalue>integer</returnvalue>
3111131111
</para>
3111231112
<para>
31113-
Returns a code explaining the reason(s) for rewriting. The exact
31114-
meaning of the codes is release dependent.
31113+
Returns a code explaining the reason(s) for rewriting. The value is
31114+
a bitmap built from the following values: <literal>1</literal>
31115+
(the table has changed its persistence), <literal>2</literal>
31116+
(default value of a column has changed), <literal>4</literal>
31117+
(a column has a new data type) and <literal>8</literal>
31118+
(the table access method has changed).
3111531119
</para></entry>
3111631120
</row>
3111731121
</tbody>

src/include/commands/event_trigger.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ typedef struct EventTriggerData
3131

3232
extern PGDLLIMPORT bool event_triggers;
3333

34+
/*
35+
* Reasons for relation rewrites.
36+
*
37+
* pg_event_trigger_table_rewrite_reason() uses these values, so make sure to
38+
* update the documentation when changing this list.
39+
*/
3440
#define AT_REWRITE_ALTER_PERSISTENCE 0x01
3541
#define AT_REWRITE_DEFAULT_VAL 0x02
3642
#define AT_REWRITE_COLUMN_REWRITE 0x04

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy