pub struct InsertIfAbsent<'a> {
pub table: &'a str,
pub columns: &'a [&'a str],
pub values: &'a [String],
pub key_columns: &'a [&'a str],
}Expand description
One row, written once — the pieces of an INSERT that must do nothing when a row already carries the same key.
The key value is not a field of its own: it is whichever values entry sits
at the same index as the key column in columns. Two fields that must agree
are two fields free to disagree, and the one they would disagree about here
is the one that decides whether a second write is a duplicate.
Fields§
§table: &'a strThe target table, already spelled the way the caller wants it written — schema-qualified or bare.
columns: &'a [&'a str]The columns being written, in the order values supplies them.
values: &'a [String]One value expression per column.
key_columns: &'a [&'a str]The columns whose equality means this row is already here.
Implementations§
Source§impl InsertIfAbsent<'_>
impl InsertIfAbsent<'_>
Sourcepub fn value_of(&self, column: &str) -> Option<&str>
pub fn value_of(&self, column: &str) -> Option<&str>
The value expression written into column, if it is being written.
Sourcepub fn key_predicate(&self, qualifier: &str) -> String
pub fn key_predicate(&self, qualifier: &str) -> String
key = value AND … — the test for already here, in terms of the
values this INSERT would have written.
qualifier prefixes the column side, which the guarded form needs so
the probe’s own row is named unambiguously.
§Panics
When a key column is not among the columns being written. A key the INSERT does not supply cannot be tested for, and silently dropping it from the predicate would make the guard match everything.
Sourcepub fn on_conflict_do_nothing(&self) -> String
pub fn on_conflict_do_nothing(&self) -> String
ON CONFLICT (key) DO NOTHING — for the platforms that let the
engine decide, which is every platform that has the clause.
The engine tests the key as it writes, so two sessions registering one file at the same moment settle on one row rather than on whichever of them looked first.
Sourcepub fn on_duplicate_key_no_op(&self) -> String
pub fn on_duplicate_key_no_op(&self) -> String
ON DUPLICATE KEY UPDATE key = key — the MySQL family’s no-op.
INSERT IGNORE would be shorter and it is not the same request: it
downgrades every error on the statement to a warning — a truncated
value, a bad date — so a row that should have been refused arrives
mangled and silent. Assigning the key to itself touches only the
collision this is about, and leaves everything else to complain
normally.
Sourcepub fn guarded_over_one_row(&self) -> String
pub fn guarded_over_one_row(&self) -> String
The guarded form over an explicit one-row source — the same
INSERT … SELECT … WHERE NOT EXISTS the portable default writes, with a
FROM clause under it.
GoogleSQL refuses a WHERE on a query that selects from nothing —
“Query without FROM clause cannot have a WHERE clause”, measured on the
live service on every generated register_file procedure — while
PostgreSQL and its cousins accept the bare form. (SELECT 1) is a
one-row table that changes no result: the guard still decides whether
the row is written, and the values are still the caller’s.
It stays a separate form rather than becoming the default because the
engines that need no FROM read better without one, and a clause every
platform carries for one platform’s sake is how a rendering stops saying
what it means.
Trait Implementations§
Source§impl<'a> Clone for InsertIfAbsent<'a>
impl<'a> Clone for InsertIfAbsent<'a>
Source§fn clone(&self) -> InsertIfAbsent<'a>
fn clone(&self) -> InsertIfAbsent<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more