-
Notifications
You must be signed in to change notification settings - Fork 549
Add limited support for PostgreSql CREATE TRIGGER and CREATE FUNCTION #5932
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
Merged
griffio
merged 20 commits into
sqldelight:master
from
griffio:fix-4812-add-postgresql-create-trigger
Sep 25, 2025
Merged
Add limited support for PostgreSql CREATE TRIGGER and CREATE FUNCTION #5932
griffio
merged 20 commits into
sqldelight:master
from
griffio:fix-4812-add-postgresql-create-trigger
Sep 25, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50430b3
to
a3662d6
Compare
Update PostgreSql.bnf CreateTrigger and Drop Trigger overrides core sql-psi Create Function is PostgreSql only
remove - "if-not-exists" has invalid syntax for PostgreSql
SchemaContributor are used to create a schema
Include any SchemaContributor implementation in extension statements like CREATE FUNCTION
DROP TRIGGER ... DROP FUNCTION ...
DROP TRIGGER ... DROP FUNCTION ...
Add mixin for SchemaContributor support Update DropFunctionMixin.kt
Support Multiple statements Add top leve `plsql_assignment` rule for future use Add `{column_expr}` to make table resolution correct
Simpler because now using `{column_expr}`
a3662d6
to
ae79f5c
Compare
Add IF ELSE ELSEIF conditionals to plsql
Add more fixture tests for trigger function conditionals
Add plsql_trigger_var_expression for trigger variables can be used as expression Add missingCURRENT_USER and SESSION_USER literals
Map literals CURRENT_USER and SESSION_USER to TEXT These variables can be accessed for audit triggers
Remove parentheses
Use a more correct conditional matching the Postgres docs example
JakeWharton
approved these changes
Sep 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not feel qualified to review this. Looks mostly fine, though.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #4812 #4795
PostgreSql Experimental 🍄😵
Very limited support for
CREATE TRIGGER
andCREATE FUNCTION
used together - not for stand-aloneCREATE FUNCTION
use.DROP TRIGGER
andDROP FUNCTION
are also supported.PostgreSql uses functions to execute the trigger DML unlike Sqlite where the trigger contains the executed statements.
Various fixes had to be made to override the Sqlite
CREATE TRIGGER
- e.g Fixtures tests that are invalid PostgreSql statements. Currently avoids the need to changesql-psi
by reusing existing public core classes.Supported Features
Call multiple statements Delete, Insert, Update e.g Insert a row into an audit table when a column is updated.
Using
new
andold
table row references are case-sensitive because SqlDelight is when referencing table names.Assign values to
new
records e.g Assign the current timestamp to a column each time a row is updated.Multiple statements e.g other assignments and deletes, inserts and updates can be mixed.
Conditionals IF ELSEIF ELSE
Add Trigger variables
Adds Extension statements (e.g CREATE FUNCTION) that implement SchemaContributor - to DataBaseGenerator isSchema check - so these are included in the body of the generated Schema
Sample.Schema.create(driver)
. As theisSchema
uses hard coded list of known statement types another way is needed to include a dialects schema statements e.g function, sequence.Adds Migration Integration Test
Notes:
plpgsql
https://www.postgresql.org/docs/current/plpgsql-trigger.htmlnotifyQueries
emit is not supported for tables in trigger function (notify is not implemented for PostgreSql anyway).CHANGELOG.md
's "Unreleased" section has been updated, if applicable.