rel8-internal
Safe HaskellNone
LanguageHaskell2010

Rel8.Internal.Statement.OnConflict

Synopsis

Documentation

data OnConflict exprs Source #

OnConflict represents the ON CONFLICT clause of an INSERT statement. This specifies what ought to happen when one or more of the rows proposed for insertion conflict with an existing row in the table.

Constructors

Abort

Abort the transaction if there are conflicting rows (Postgres' default)

DoNothing (Maybe (Conflict exprs))

ON CONFLICT DO NOTHING, or ON CONFLICT (...) DO NOTHING if an explicit conflict target is supplied. Specifying a conflict target is essential when your table has has deferrable constraints — ON CONFLICT can't work on deferrable constraints, so it's necessary to explicitly name one of its non-deferrable constraints in order to use ON CONFLICT.

DoUpdate (Upsert exprs)
ON CONFLICT (...) DO UPDATE ...

data Conflict exprs Source #

Represents what PostgreSQL calls a conflict_target in an ON CONFLICT clause of an INSERT statement.

Constructors

OnConstraint String

Use a specific named constraint for the conflict target. This corresponds the the syntax ON CONFLICT constraint in PostgreSQL.

OnIndex (Index exprs)

Have PostgreSQL perform what it calls _unique index inference_ by giving it a description of the target index.

data Index exprs where Source #

A description of the target unique index — its columns (and/or expressions) and, in the case of partial indexes, a predicate.

Constructors

Index 

Fields

data Upsert exprs where Source #

The ON CONFLICT (...) DO UPDATE clause of an INSERT statement, also known as "upsert".

When an existing row conflicts with a row proposed for insertion, ON CONFLICT DO UPDATE allows you to instead update this existing row. The conflicting row proposed for insertion is then "excluded", but its values can still be referenced from the SET and WHERE clauses of the UPDATE statement.

Upsert in Postgres a "conflict target" to be specified — this is the UNIQUE index from conflicts with which we would like to recover. Indexes are specified by listing the columns that comprise them along with an optional predicate in the case of partial indexes.

Constructors

Upsert 

Fields

  • :: forall excluded exprs. excluded ~ exprs
     
  • => { conflict :: Conflict exprs

    The conflict target to supply to DO UPDATE.

  •    , set :: excluded -> exprs -> exprs

    How to update each selected row.

  •    , updateWhere :: excluded -> exprs -> Expr Bool

    Which rows to select for update.

  •    } -> Upsert exprs
     

ppOnConflict :: Selects names exprs => TableSchema names -> OnConflict exprs -> Doc Source #