Skip to content

Provide a function to emit DDL for CREATE EVENT TRIGGER#1

Open
drpalaric wants to merge 1 commit intomasterfrom
dev/PG-158
Open

Provide a function to emit DDL for CREATE EVENT TRIGGER#1
drpalaric wants to merge 1 commit intomasterfrom
dev/PG-158

Conversation

@drpalaric
Copy link
Owner

This patch implements the pg_get_event_trigger_ddl() function, which emits the DDL for CREATE EVENT TRIGGER.
It includes documentation and tests.

PG-158

Author: Ian Barwick barwick@gmail.com
Co-authored-by: Phil Alger phil.alger@enterprisedb.com

@drpalaric drpalaric force-pushed the dev/PG-158 branch 3 times, most recently from 71e2b03 to f3d9da2 Compare September 28, 2025 14:15
@drpalaric drpalaric force-pushed the dev/PG-158 branch 3 times, most recently from 1466737 to a5c96cc Compare September 30, 2025 21:34
</para>
<para>
Reconstructs the underlying DDL statement for a specified event trigger.
It returns the complete CREATE EVENT TRIGGER statement. For example,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if the example will be seen as too much info for the function documentation, as if output examples are provided at all they tend to be one-liners (see e.g https://www.postgresql.org/docs/current/functions-info.html#FUNCTIONS-INFO-CATALOG-TABLE ), and a dozen or so retail DDL functions all with their own examples might look a bit bloated and repetitive.

(Personally I'm all in favour of examples for everything, but the Pg docs structure for functions in particular is not very conducive to that).

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am also. what do you think @alvherre ?

<primary>pg_get_event_trigger_ddl</primary>
</indexterm>
<function>pg_get_event_trigger_ddl</function>
(<parameter>event trigger name</parameter> <type>name</type>)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use of the name type is clever; I wonder if all the retail DDL functions should take type name?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the function parameter corresponds to a (system catalogue) column of type name (and there's no corresponding regXXX object identifier type), then it should be defined as such.

<primary>pg_get_event_trigger_ddl</primary>
</indexterm>
<function>pg_get_event_trigger_ddl</function>
(<parameter>event trigger name</parameter> <type>name</type>)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameter name should be joined with underscores, i.e. <parameter>event_trigger_name</parameter>.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link

@akshay-joshi akshay-joshi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR contains extra whitespace. Could you please run pgindent to clean it up?

@drpalaric drpalaric force-pushed the dev/PG-158 branch 2 times, most recently from f664e94 to b2382b0 Compare October 3, 2025 19:06
@drpalaric
Copy link
Owner Author

Removed whitespace

This patch implements the pg_get_event_trigger_ddl() function, which emits
the DDL for CREATE EVENT TRIGGER. It includes functionality comments in the code,
as well as tests and documentation.

The returned function will look like the following:

postgres=# SELECT pg_get_event_trigger_ddl('foo_event_trigger');
                                           pg_get_event_trigger_ddl
---------------------------------------------------------------------------------------------------------------
 CREATE EVENT TRIGGER foo_event_trigger ON ddl_command_start EXECUTE FUNCTION public.test_event_trigger();
(1 row)

or with a TAG filter:

postgres=# SELECT pg_get_event_trigger_ddl('foo_event_trigger2');
                                                                   pg_get_event_trigger_ddl
---------------------------------------------------------------------------------------------------------------------------------------------------------------
 CREATE EVENT TRIGGER foo_event_trigger2 ON ddl_command_start WHEN TAG IN ('CREATE TABLE','CREATE FUNCTION') EXECUTE FUNCTION public.test_event_trigger();

PG-158

Author: Ian Barwick <barwick@gmail.com>
Co-authored-by: Phil Alger <phil.alger@enterprisedb.com>
drpalaric pushed a commit that referenced this pull request Oct 9, 2025
truncate_useless_pathkeys() seems to have neglected to account for
PathKeys that might be useful for WindowClause evaluation.  Modify it so
that it properly accounts for that.

Making this work required adjusting two things:

1. Change from checking query_pathkeys to check sort_pathkeys instead.
2. Add explicit check for window_pathkeys

For #1, query_pathkeys gets set in standard_qp_callback() according to the
sort order requirements for the first operation to be applied after the
join planner is finished, so this changes depending on which upper
planner operations a particular query needs.  If the query has window
functions and no GROUP BY, then query_pathkeys gets set to
window_pathkeys.  Before this change, this meant PathKeys useful for the
ORDER BY were not accounted for in queries with window functions.

Because of #1, #2 is now required so that we explicitly check to ensure
we don't truncate away PathKeys useful for window functions.

Author: David Rowley <dgrowleyml@gmail.com>
Discussion: https://postgr.es/m/CAApHDvrj3HTKmXoLMbUjTO=_MNMxM=cnuCSyBKidAVibmYPnrg@mail.gmail.com
drpalaric pushed a commit that referenced this pull request Jan 30, 2026
cost_tidrangescan() was setting the disabled_nodes value correctly,
and then immediately resetting it to zero, due to poor code editing on
my part.

materialized_finished_plan correctly set matpath.parent to
zero, but forgot to also set matpath.parallel_workers = 0, causing
an access to uninitialized memory in cost_material. (This shouldn't
result in any real problem, but it makes valgrind unhappy.)

reparameterize_path was dereferencing a variable before verifying that
it was not NULL.

Reported-by: Tom Lane <tgl@sss.pgh.pa.us> (issue #1)
Reported-by: Michael Paquier <michael@paquier.xyz> (issue #1)
Diagnosed-by: Lukas Fittl <lukas@fittl.com> (issue #1)
Reported-by: Zsolt Parragi <zsolt.parragi@percona.com> (issue #2)
Reported-by: Richard Guo <guofenglinux@gmail.com> (issue #3)
Discussion: http://postgr.es/m/CAN4CZFPvwjNJEZ_JT9Y67yR7C=KMNa=LNefOB8ZY7TKDcmAXOA@mail.gmail.com
Discussion: http://postgr.es/m/aXrnPgrq6Gggb5TG@paquier.xyz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants