From 5e45211a64149b3c659b90ff2de6fa982a5a93ed Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 4 May 2024 14:17:33 +0200 Subject: Adding upstream version 15.5. Signed-off-by: Daniel Baumann --- doc/src/sgml/html/functions-event-triggers.html | 133 ++++++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 doc/src/sgml/html/functions-event-triggers.html (limited to 'doc/src/sgml/html/functions-event-triggers.html') diff --git a/doc/src/sgml/html/functions-event-triggers.html b/doc/src/sgml/html/functions-event-triggers.html new file mode 100644 index 0000000..de23b5f --- /dev/null +++ b/doc/src/sgml/html/functions-event-triggers.html @@ -0,0 +1,133 @@ + +9.29. Event Trigger Functions

9.29. Event Trigger Functions

+ PostgreSQL provides these helper functions + to retrieve information from event triggers. +

+ For more information about event triggers, + see Chapter 40. +

9.29.1. Capturing Changes at Command End

+pg_event_trigger_ddl_commands () → setof record
+

+ pg_event_trigger_ddl_commands returns a list of + DDL commands executed by each user action, + when invoked in a function attached to a + ddl_command_end event trigger. If called in any other + context, an error is raised. + pg_event_trigger_ddl_commands returns one row for each + base command executed; some commands that are a single SQL sentence + may return more than one row. This function returns the following + columns: + +

NameTypeDescription
classidoidOID of catalog the object belongs in
objidoidOID of the object itself
objsubidintegerSub-object ID (e.g., attribute number for a column)
command_tagtextCommand tag
object_typetextType of the object
schema_nametext + Name of the schema the object belongs in, if any; otherwise NULL. + No quoting is applied. +
object_identitytext + Text rendering of the object identity, schema-qualified. Each + identifier included in the identity is quoted if necessary. +
in_extensionbooleanTrue if the command is part of an extension script
commandpg_ddl_command + A complete representation of the command, in internal format. + This cannot be output directly, but it can be passed to other + functions to obtain different pieces of information about the + command. +

+

9.29.2. Processing Objects Dropped by a DDL Command

+pg_event_trigger_dropped_objects () → setof record
+

+ pg_event_trigger_dropped_objects returns a list of all objects + dropped by the command in whose sql_drop event it is called. + If called in any other context, an error is raised. + This function returns the following columns: + +

NameTypeDescription
classidoidOID of catalog the object belonged in
objidoidOID of the object itself
objsubidintegerSub-object ID (e.g., attribute number for a column)
originalbooleanTrue if this was one of the root object(s) of the deletion
normalboolean + True if there was a normal dependency relationship + in the dependency graph leading to this object +
is_temporaryboolean + True if this was a temporary object +
object_typetextType of the object
schema_nametext + Name of the schema the object belonged in, if any; otherwise NULL. + No quoting is applied. +
object_nametext + Name of the object, if the combination of schema and name can be + used as a unique identifier for the object; otherwise NULL. + No quoting is applied, and name is never schema-qualified. +
object_identitytext + Text rendering of the object identity, schema-qualified. Each + identifier included in the identity is quoted if necessary. +
address_namestext[] + An array that, together with object_type and + address_args, can be used by + the pg_get_object_address function to + recreate the object address in a remote server containing an + identically named object of the same kind. +
address_argstext[] + Complement for address_names +

+

+ The pg_event_trigger_dropped_objects function can be used + in an event trigger like this: +

+CREATE FUNCTION test_event_trigger_for_drops()
+        RETURNS event_trigger LANGUAGE plpgsql AS $$
+DECLARE
+    obj record;
+BEGIN
+    FOR obj IN SELECT * FROM pg_event_trigger_dropped_objects()
+    LOOP
+        RAISE NOTICE '% dropped object: % %.% %',
+                     tg_tag,
+                     obj.object_type,
+                     obj.schema_name,
+                     obj.object_name,
+                     obj.object_identity;
+    END LOOP;
+END;
+$$;
+CREATE EVENT TRIGGER test_event_trigger_for_drops
+   ON sql_drop
+   EXECUTE FUNCTION test_event_trigger_for_drops();
+

+

9.29.3. Handling a Table Rewrite Event

+ The functions shown in + Table 9.102 + provide information about a table for which a + table_rewrite event has just been called. + If called in any other context, an error is raised. +

Table 9.102. Table Rewrite Information Functions

+ Function +

+

+ Description +

+ + pg_event_trigger_table_rewrite_oid () + → oid +

+

+ Returns the OID of the table about to be rewritten. +

+ + pg_event_trigger_table_rewrite_reason () + → integer +

+

+ Returns a code explaining the reason(s) for rewriting. The exact + meaning of the codes is release dependent. +


+ These functions can be used in an event trigger like this: +

+CREATE FUNCTION test_event_trigger_table_rewrite_oid()
+ RETURNS event_trigger
+ LANGUAGE plpgsql AS
+$$
+BEGIN
+  RAISE NOTICE 'rewriting table % for reason %',
+                pg_event_trigger_table_rewrite_oid()::regclass,
+                pg_event_trigger_table_rewrite_reason();
+END;
+$$;
+
+CREATE EVENT TRIGGER test_table_rewrite_oid
+                  ON table_rewrite
+   EXECUTE FUNCTION test_event_trigger_table_rewrite_oid();
+

+

\ No newline at end of file -- cgit v1.2.3