Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oT16N-0004qx-FF for pgsql-hackers@arkaria.postgresql.org; Tue, 30 Aug 2022 13:16:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oT16M-0005Z8-Ci for pgsql-hackers@arkaria.postgresql.org; Tue, 30 Aug 2022 13:16:22 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oT16M-0005Yq-2l for pgsql-hackers@lists.postgresql.org; Tue, 30 Aug 2022 13:16:22 +0000 Received: from feynman.df7cb.de ([195.49.152.168]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oT16J-00083r-2M for pgsql-hackers@lists.postgresql.org; Tue, 30 Aug 2022 13:16:21 +0000 Received: from msg.df7cb.de (unknown [IPv6:2003:5b:203b:100:7627:eaff:fe52:8e03]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) by feynman.df7cb.de (Postfix) with ESMTPSA id 4MH79Z0fdXz3F5G for ; Tue, 30 Aug 2022 15:16:18 +0200 (CEST) Date: Tue, 30 Aug 2022 15:16:17 +0200 From: Christoph Berg To: PostgreSQL Hackers Subject: plpgsql-trigger.html: Format TG_ variables as table (patch) Message-ID: Mail-Followup-To: Christoph Berg , PostgreSQL Hackers MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="oKS2aQhvqmkYhKf+" Content-Disposition: inline List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --oKS2aQhvqmkYhKf+ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi, I found the list of TG_ variables on https://www.postgresql.org/docs/current/plpgsql-trigger.html#PLPGSQL-DML-TRIGGER hard to read for several reasons: too much whitespace, all the lines start with "Data type", and even after that, the actual content is hiding behind some extra "variable that..." boilerplate. The attached patch formats the list as a table, and removes some of the clutter from the text. I reused the catalog_table_entry table machinery, that is probably not quite the correct thing, but I didn't find a better variant, and the result looks ok. Thanks to ilmari for the idea and some initial reviews. Christoph --oKS2aQhvqmkYhKf+ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-plpgsql-trigger.html-Format-TG_-variables-as-table.patch" From 708c05277e6e2a93e9ceb1e52fda5991cef8b545 Mon Sep 17 00:00:00 2001 From: Christoph Berg Date: Tue, 30 Aug 2022 15:09:39 +0200 Subject: [PATCH] plpgsql-trigger.html: Format TG_ variables as table Format list as table, and remove redundant clutter ("viarable holding...") that made the list hard to skim --- doc/src/sgml/plpgsql.sgml | 221 ++++++++++++++++++++------------------ 1 file changed, 114 insertions(+), 107 deletions(-) diff --git a/doc/src/sgml/plpgsql.sgml b/doc/src/sgml/plpgsql.sgml index cf387dfc3f..c73e81eff0 100644 --- a/doc/src/sgml/plpgsql.sgml +++ b/doc/src/sgml/plpgsql.sgml @@ -4028,142 +4028,149 @@ ASSERT condition , When a PL/pgSQL function is called as a trigger, several special variables are created automatically in the - top-level block. They are: + top-level block. They are listed in . + - - - NEW - + + <structname>TG_</structname> special trigger function variables + + + + + Variable Type + - Data type RECORD; variable holding the new - database row for INSERT/UPDATE operations in row-level - triggers. This variable is null in statement-level triggers - and for DELETE operations. + Description + + + + + + + + NEW record - - - - - OLD - - Data type RECORD; variable holding the old - database row for UPDATE/DELETE operations in row-level + new database row for INSERT/UPDATE operations in row-level triggers. This variable is null in statement-level triggers - and for INSERT operations. - - - + and for DELETE operations. + + - - TG_NAME - + + + OLD record + - Data type name; variable that contains the name of the trigger actually - fired. + old database row for UPDATE/DELETE operations in row-level + triggers. This variable is null in statement-level triggers and for INSERT + operations. + + + + + + TG_NAME name - - + + name of the trigger fired. + + - - TG_WHEN - + + + TG_WHEN text + - Data type text; a string of - BEFORE, AFTER, or + string BEFORE, AFTER, or INSTEAD OF, depending on the trigger's definition. - - - + + - - TG_LEVEL - + + + TG_LEVEL text + - Data type text; a string of either - ROW or STATEMENT - depending on the trigger's definition. + string ROW or STATEMENT depending + on the trigger's definition. + + + + + + TG_OP text - - - - - TG_OP - - Data type text; a string of - INSERT, UPDATE, + string INSERT, UPDATE, DELETE, or TRUNCATE telling for which operation the trigger was fired. - - - + + - - TG_RELID - - - Data type oid; the object ID of the table that caused the - trigger invocation. + + + TG_RELID oid + (references pg_class.oid) - - - - - TG_RELNAME - - Data type name; the name of the table that caused the trigger - invocation. This is now deprecated, and could disappear in a future - release. Use TG_TABLE_NAME instead. - - - + object ID of the table that caused the trigger invocation. + + - - TG_TABLE_NAME - - - Data type name; the name of the table that - caused the trigger invocation. + + + TG_RELNAME name - - - - - TG_TABLE_SCHEMA - - Data type name; the name of the schema of the - table that caused the trigger invocation. + name of the table that caused the trigger invocation. This is now + deprecated, and could disappear in a future release. Use + TG_TABLE_NAME instead. + + + + + + TG_TABLE_NAME name - - - - - TG_NARGS - - Data type integer; the number of arguments given to the trigger - function in the CREATE TRIGGER statement. + name of the table that caused the trigger invocation. + + + + + + TG_TABLE_SCHEMA name - - + + name of the schema of the table that caused the trigger invocation. + + - - TG_ARGV[] - + + + TG_NARGS integer + - Data type array of text; the arguments from - the CREATE TRIGGER statement. - The index counts from 0. Invalid - indexes (less than 0 or greater than or equal to tg_nargs) - result in a null value. + number of arguments given to the trigger function in the + CREATE TRIGGER statement. + + + + + + TG_ARGV text[] - - - - + + arguments from the CREATE TRIGGER statement. The + index counts from 0. Invalid indexes (less than 0 or greater than or + equal to tg_nargs) result in a null value. + + + + + +
A trigger function must return either NULL or a -- 2.35.1 --oKS2aQhvqmkYhKf+--