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

Postgres Triggers, achieve different behaviour on INSERT, UPDATE, etc. #409

Open
hohmannr opened this issue Apr 7, 2024 · 0 comments
Open

Comments

@hohmannr
Copy link

hohmannr commented Apr 7, 2024

In the current plrust docs, I have found the following example for triggers:

    let tg_op = trigger.op()?;

    let my_row = match tg_op {
        INSERT => trigger.new().unwrap(),
        _ => trigger.old().unwrap()
    };

This does not get you different behaviour for different trigger ops, since the matchstatement's _ option is unreachable, because INSERT is treated as a variable, that catches tg_ops value. Looking into this, I have found the following to work:

    let tg_op = trigger.op()?;

    let my_row = match tg_op {
        PgTriggerOperation::Insert => trigger.new().unwrap(),
        PgTriggerOperation::Update=> trigger.old().unwrap(),
        _ => error!("unsupported trigger operation!"),
    };

My specs: Using plrust on AWS RDS: postgres v15.5

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

No branches or pull requests

1 participant