squeal-postgresql-0.5.2.0: Squeal PostgreSQL Library

Copyright(c) Eitan Chatav 2019
Maintainereitan@morphism.tech
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

Squeal.PostgreSQL.Expression.Null

Description

Null values and null handling functions

Synopsis

Documentation

null_ :: Expr (Null ty) Source #

analagous to Nothing

>>> printSQL null_
NULL

notNull :: NotNull ty :--> Null ty Source #

analagous to Just

>>> printSQL $ notNull true
TRUE

coalesce :: FunctionVar (Null ty) (NotNull ty) (NotNull ty) Source #

return the leftmost value which is not NULL

>>> printSQL $ coalesce [null_, true] false
COALESCE(NULL, TRUE, FALSE)

fromNull Source #

Arguments

:: Expression outer commons grp schemas params from (NotNull ty)

what to convert NULL to

-> Expression outer commons grp schemas params from (Null ty) 
-> Expression outer commons grp schemas params from (NotNull ty) 

analagous to fromMaybe using COALESCE

>>> printSQL $ fromNull true null_
COALESCE(NULL, TRUE)

isNull :: Null ty :--> null PGbool Source #

>>> printSQL $ null_ & isNull
NULL IS NULL

isNotNull :: Null ty :--> null PGbool Source #

>>> printSQL $ null_ & isNotNull
NULL IS NOT NULL

matchNull Source #

Arguments

:: Expression outer commons grp schemas params from nullty

what to convert NULL to

-> (Expression outer commons grp schemas params from (NotNull ty) -> Expression outer commons grp schemas params from nullty)

function to perform when NULL is absent

-> Expression outer commons grp schemas params from (Null ty) 
-> Expression outer commons grp schemas params from nullty 

analagous to maybe using IS NULL

>>> printSQL $ matchNull true not_ null_
CASE WHEN NULL IS NULL THEN TRUE ELSE (NOT NULL) END

nullIf :: FunctionN '[NotNull ty, NotNull ty] (Null ty) Source #

right inverse to fromNull, if its arguments are equal then nullIf gives NULL.

>>> :set -XTypeApplications -XDataKinds
>>> let expr = nullIf (false *: param @1) :: Expression outer commons grp schemas '[ 'NotNull 'PGbool] from ('Null 'PGbool)
>>> printSQL expr
NULLIF(FALSE, ($1 :: bool))