Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Postgres Translate Insert
Translates IR inserts to Postgres-specific SQL INSERT statements.
Synopsis
- mkInsertCTE :: Backend ('Postgres pgKind) => InsertQueryP1 ('Postgres pgKind) -> TopLevelCTE
- toSQLConflict :: Backend ('Postgres pgKind) => QualifiedTable -> OnConflictClause ('Postgres pgKind) SQLExp -> SQLConflict
- insertCheckConstraint :: BoolExp -> SQLExp
- insertOrUpdateCheckExpr :: QualifiedTable -> Maybe (OnConflictClause ('Postgres pgKind) SQLExp) -> BoolExp -> Maybe BoolExp -> Extractor
Documentation
mkInsertCTE :: Backend ('Postgres pgKind) => InsertQueryP1 ('Postgres pgKind) -> TopLevelCTE Source #
toSQLConflict :: Backend ('Postgres pgKind) => QualifiedTable -> OnConflictClause ('Postgres pgKind) SQLExp -> SQLConflict Source #
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.