graphql-engine-1.0.0: GraphQL API over Postgres
Safe HaskellSafe-Inferred
LanguageHaskell2010

Hasura.Backends.Postgres.Translate.Insert

Description

Postgres Translate Insert

Translates IR inserts to Postgres-specific SQL INSERT statements.

Synopsis

Documentation

insertCheckConstraint :: BoolExp -> SQLExp Source #

Annotates the check constraint expression with boolean (check-condition)::boolean

insertOrUpdateCheckExpr :: QualifiedTable -> Maybe (OnConflictClause ('Postgres pgKind) SQLExp) -> BoolExp -> Maybe BoolExp -> Extractor Source #

When inserting data, we might need to also enforce the update check condition, because we might fall back to an update via an ON CONFLICT clause.

We generate something which looks like

INSERT INTO
  ...
ON CONFLICT DO UPDATE SET
  ...
RETURNING
  *,
  CASE WHEN xmax = 0
    THEN {insert_cond}
    ELSE {update_cond}
  END
    AS "check__constraint"

See https://stackoverflow.com/q/34762732 for more information on the use of the xmax system column.