Skip to content

Commit bca8026

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 ca643bc commit bca8026

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
@@ -80,6 +80,11 @@
8080
control statements are available to rewrite a table,
8181
like <literal>CLUSTER</literal> and <literal>VACUUM</literal>,
8282
the <literal>table_rewrite</literal> event is not triggered by them.
83+
To find the OID of the table that was rewritten, use the function
84+
<literal>pg_event_trigger_table_rewrite_oid()</literal> (see
85+
<xref linkend="functions-event-triggers"/>). To discover the reason(s)
86+
for the rewrite, use the function
87+
<literal>pg_event_trigger_table_rewrite_reason()</literal>.
8388
</para>
8489

8590
<para>

doc/src/sgml/func.sgml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27783,8 +27783,12 @@ CREATE EVENT TRIGGER test_event_trigger_for_drops
2778327783
<returnvalue>integer</returnvalue>
2778427784
</para>
2778527785
<para>
27786-
Returns a code explaining the reason(s) for rewriting. The exact
27787-
meaning of the codes is release dependent.
27786+
Returns a code explaining the reason(s) for rewriting. The value is
27787+
a bitmap built from the following values: <literal>1</literal>
27788+
(the table has changed its persistence), <literal>2</literal>
27789+
(default value of a column has changed), <literal>4</literal>
27790+
(a column has a new data type) and <literal>8</literal>
27791+
(the table access method has changed).
2778827792
</para></entry>
2778927793
</row>
2779027794
</tbody>

src/include/commands/event_trigger.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ typedef struct EventTriggerData
2929
CommandTag tag;
3030
} EventTriggerData;
3131

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

0 commit comments

Comments
 (0)