pub fn old_value<C: Column>(col: C) -> old_value<C>Available on crate feature
mariadb_backend only.Expand description
Refer to the pre-modification value of col in a Mariadb RETURNING
clause.
This corresponds to the SQL RETURNING OLD_VALUE(col) syntax introduced in
Mariadb 13.0.
§Requires Mariadb 13.0 or newer
Diesel emits OLD_VALUE(col) in the SQL it sends to the database. Earlier
versions of Mariadb will reject the query at execution time.
§Statement compatibility
old_value(col) is valid inside the RETURNING clause of:
- an
UPDATEstatement, as a wholeRETURNINGitem that loads into the same Rust types ascol(since every returned row necessarily came from a pre-existing row).
Use of old_value(col) in INSERT or DELETE RETURNING
is rejected at compile time, because it is invalid
there. (Note that ON CONFLICT DO NOTHING never returns untouched rows.)
On MariaDB 13.0, old_value of a view column that is an expression or a
constant crashes the server
(MDEV-40125). MariaDB 13.1.1
returns the right value.
§Example
let was_and_now = diesel::update(users.find(1))
.set(name.eq("Updated"))
.returning((old_value(name), name))
.get_result::<(String, String)>(connection);
assert_eq!(Ok(("Sean".to_string(), "Updated".to_string())), was_and_now);