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!"),
};
In the current plrust docs, I have found the following example for triggers:
This does not get you different behaviour for different trigger ops, since the
match
statement's_
option is unreachable, becauseINSERT
is treated as a variable, that catchestg_op
s value. Looking into this, I have found the following to work:My specs: Using plrust on AWS RDS: postgres v15.5