Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PostgreSQL support for CREATE TRIGGER and DROP TRIGGER #15351

Closed
11 of 12 tasks
lukaseder opened this issue Jul 6, 2023 · 0 comments
Closed
11 of 12 tasks

Add PostgreSQL support for CREATE TRIGGER and DROP TRIGGER #15351

lukaseder opened this issue Jul 6, 2023 · 0 comments

Comments

@lukaseder
Copy link
Member

lukaseder commented Jul 6, 2023

PostgreSQL doesn't support inline trigger bodies, only references to stored functions "returning a trigger," see:

For this reason, we haven't supported them yet in our DDL API, because ordinary triggers from other RDBMS can't be mapped to PostgreSQL easily.

jOOQ 3.19 now adds more support for triggers, e.g. in the form of runtime meta model / code generation support:

This means it would be great (e.g. for integration testing), if we could support PG triggers anyway as follow:

  • There's a naming convention for trigger_name -> trigger_name_function
  • jOOQ controls the lifecycle of the trigger function, assuming it is never manipulated outside of jOOQ
    • Creating the trigger creates the function
      • Caveat: The function has to be re-created when the trigger doesn't exist. This could happen, for example, when the table is dropped and re-created, in case of which the trigger is also dropped, but not the trigger function!
    • Dropping the trigger drops the function

Related

Caveats:

Unresolved caveats:

  • Dropping a table doesn't cascade to deleting the trigger function. I'm not sure if this can be done?
    • But it means that we must always CREATE OR REPLACE the trigger function (nope, the function is created before the trigger, so CREATE OR REPLACE would succeed even if CREATE TRIGGER fails)
@lukaseder lukaseder added this to the Version 3.19.0 milestone Jul 6, 2023
@lukaseder lukaseder added this to To do in 3.13 DDL interpretation via automation Jul 6, 2023
lukaseder added a commit that referenced this issue Jul 7, 2023
lukaseder added a commit that referenced this issue Jul 7, 2023
lukaseder added a commit that referenced this issue Nov 22, 2023
- DELETE triggers should RETURN OLD, not RETURN NEW
- Clean up stale trigger functions, if their trigger doesn't exist
lukaseder added a commit that referenced this issue Nov 22, 2023
See also [#15351], where procedural QOM types are necessary for PostgreSQL trigger support
lukaseder added a commit that referenced this issue Nov 22, 2023
This includes:

- [#15351] Decide based on the TG_OP whether to RETURN NEW or RETURN OLD in PostgreSQL
3.13 DDL interpretation automation moved this from To do to Done Nov 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment