Skip to main content

ConflictClause

Struct ConflictClause 

Source
pub struct ConflictClause {
    pub target: ConflictTarget,
    pub action: Option<ConflictAction>,
    pub set: Set,
    pub where_: Where,
}
Expand description

ON CONFLICT [<target>] DO NOTHING | DO UPDATE SET … [WHERE …]

From PostgreSQL 17, https://www.postgresql.org/docs/17/sql-insert.html:

ON CONFLICT [ conflict_target ] conflict_action

conflict_target: ( { index_column_name | ( index_expression ) } [ COLLATE … ] [ opclass ] [, ...] )
                   [ WHERE index_predicate ]
               | ON CONSTRAINT constraint_name
conflict_action: DO NOTHING
               | DO UPDATE SET { … } [, ...] [ WHERE condition ]

The two halves are easy to conflate and behave nothing alike. The target is an index inference — which unique index the conflict is detected on — and its WHERE is the index’s predicate, matched against the index rather than evaluated per row. The action’s WHERE filters which conflicting rows get updated. Both are WHEREs in the same clause, and both are reachable through HasWhere here: on ConflictTarget for the first, on ConflictClause for the second.

DO UPDATE also requires at least one assignment, which is checked rather than rendered into a syntax error.

Fields§

§target: ConflictTarget

Which conflicts this handles. Absent means any.

§action: Option<ConflictAction>

What to do. None is how a default-constructed clause stays absent: there is no ON CONFLICT without an action.

§set: Set

The assignments of DO UPDATE.

§where_: Where

Which conflicting rows DO UPDATE applies to.

Implementations§

Source§

impl ConflictClause

Source

pub fn do_nothing() -> Self

ON CONFLICT … DO NOTHING.

Source

pub fn do_update() -> Self

ON CONFLICT … DO UPDATE SET …. The assignments still have to be added.

Source

pub fn is_empty(&self) -> bool

Whether the clause is absent.

Trait Implementations§

Source§

impl Clone for ConflictClause

Source§

fn clone(&self) -> ConflictClause

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ConflictClause

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ConflictClause

Source§

fn default() -> ConflictClause

Returns the “default value” for a type. Read more
Source§

impl Expression for ConflictClause

Source§

fn write_sql(&self, w: &mut SqlWriter<'_>)

Append this fragment to w. Read more
Source§

impl HasConflictClause for ConflictClause

Source§

fn conflict_clause_mut(&mut self) -> &mut ConflictClause

The conflict clause to modify.
Source§

impl HasSet for ConflictClause

Source§

fn set_mut(&mut self) -> &mut Set

The assignment list to modify.
Source§

impl HasWhere for ConflictClause

Source§

fn where_mut(&mut self) -> &mut Where

The WHERE clause to modify.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.