plrust
plrust copied to clipboard
Postgres Triggers, achieve different behaviour on INSERT, UPDATE, etc.
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 match
statement's _
option is unreachable, because INSERT
is treated as a variable, that catches tg_op
s 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