Skip to content

Trigger generation for PostgreSQL is not idempotent #102

@hlampert

Description

@hlampert

The SQL generation script for PostgreSQL can't be repeatedly run, because the triggers are not dropped before the corresponding CREATE TRIGGER statement. There are DROP TRIGGER IF EXISTS statements in the code, however they are commented out. There are also commented out DROP FUNCTION IF EXISTS statements for the corresponding trigger functions, however the functions have are managed by CREATE OR REPLACE FUNCTION blocks, so there is no need for them to be dropped first. Unfortunately, there is no CREATE OR REPLACE TRIGGER statement, so the triggers do need to be dropped and recreated if they exist.

My guess was the original flow was to drop and recreate both the triggers and the functions. The flow was then changed so that functions were created or replaced, however the triggers were not and this was not tested by repeatedly running a generated script on a database.

The solution that seems to work is to not comment out the DROP TRIGGER IF EXISTS statements during script generation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions