pub struct InsertQuery {
pub hints: Hints,
pub modifiers: Modifiers,
pub table: TableRef,
pub values: Values,
pub set: Set,
pub row_alias: RowAlias,
pub duplicate_key_update: Set,
}Expand description
A MySQL INSERT.
From https://dev.mysql.com/doc/refman/8.4/en/insert.html, with the three row sources folded together:
INSERT [hint_comment] [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE]
[INTO] tbl_name
[PARTITION (partition_name [, partition_name] ...)]
[(col_name [, col_name] ...)]
{ {VALUES | VALUE} (value_list) [, (value_list)] ...
| SET assignment_list
| [(col_name [, col_name] ...)] { SELECT ... | TABLE tbl | VALUES row_list } }
[AS row_alias[(col_alias [, col_alias] ...)]]
[ON DUPLICATE KEY UPDATE assignment_list]INTO is written unconditionally even though the grammar makes it optional:
the shorter form saves four characters and costs a reader a double-take.
§Three row sources, one field each
VALUES, a query, and SET are alternatives. Values holds the first two;
set is the third, and it wins when both are present, because
a half-and-half rendering is not a statement. With none of them, VALUES () is
written — MySQL’s spelling of “every column takes its default”, which
PostgreSQL spells DEFAULT VALUES.
Choosing SET also drops the insert column list, because the SET production
does not have one: INSERT INTO t (a) SET b = 1 is a syntax error, not a
statement with a redundant clause. PARTITION is in both productions and stays.
§No WITH
MySQL permits a CTE only immediately before the SELECT of an
INSERT … SELECT, never in front of the INSERT (15.2.20). So there is no
with field and no insert::with mod; put the WITH on the sub-query given
to insert::query.
Fields§
§hints: Hints/*+ … */.
modifiers: ModifiersLOW_PRIORITY / HIGH_PRIORITY / DELAYED, and IGNORE.
table: TableRefThe target: table, partitions, and the insert column list.
values: ValuesThe rows, or the query to insert the results of.
set: SetSET a = 1, b = 2, the assignment-list row source.
row_alias: RowAliasAS row_alias [(cols)].
duplicate_key_update: SetON DUPLICATE KEY UPDATE ….
Implementations§
Source§impl InsertQuery
impl InsertQuery
Sourcepub fn new() -> InsertQuery
pub fn new() -> InsertQuery
An INSERT with nothing set yet.
Sourcepub fn apply(&mut self, mods: impl Mod<InsertQuery>)
pub fn apply(&mut self, mods: impl Mod<InsertQuery>)
Apply more mods to an existing query.
Trait Implementations§
Source§impl Clone for InsertQuery
impl Clone for InsertQuery
Source§fn clone(&self) -> InsertQuery
fn clone(&self) -> InsertQuery
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for InsertQuery
impl Debug for InsertQuery
Source§impl Default for InsertQuery
impl Default for InsertQuery
Source§fn default() -> InsertQuery
fn default() -> InsertQuery
Source§impl Expression for InsertQuery
impl Expression for InsertQuery
Source§impl HasDuplicateKeyUpdate for InsertQuery
impl HasDuplicateKeyUpdate for InsertQuery
Source§fn duplicate_key_update_mut(&mut self) -> &mut Set
fn duplicate_key_update_mut(&mut self) -> &mut Set
ON DUPLICATE KEY UPDATE assignments.Source§impl HasHints for InsertQuery
impl HasHints for InsertQuery
Source§impl HasModifiers for InsertQuery
impl HasModifiers for InsertQuery
Source§fn modifiers_mut(&mut self) -> &mut Modifiers
fn modifiers_mut(&mut self) -> &mut Modifiers
Source§impl HasRowAlias for InsertQuery
impl HasRowAlias for InsertQuery
Source§fn row_alias_mut(&mut self) -> &mut RowAlias
fn row_alias_mut(&mut self) -> &mut RowAlias
Source§impl HasSet for InsertQuery
The INSERT … SET row source, not the ON DUPLICATE KEY UPDATE list —
see HasDuplicateKeyUpdate.
impl HasSet for InsertQuery
The INSERT … SET row source, not the ON DUPLICATE KEY UPDATE list —
see HasDuplicateKeyUpdate.