Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NULLS FIRST / NULLS LAST qualifiers for ordering #341

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/Database/Esqueleto/PostgreSQL.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ module Database.Esqueleto.PostgreSQL
, insertSelectWithConflictCount
, filterWhere
, values
, ascNullsFirst
, ascNullsLast
, descNullsFirst
, descNullsLast
-- * Internal
, unsafeSqlAggregateFunction
) where
Expand Down Expand Up @@ -434,3 +438,21 @@ values exprs = Ex.From $ do
<> "(" <> TLB.fromLazyText colsAliases <> ")"
, params
)

-- | Ascending order of this field or SqlExpression with nulls coming first.
ascNullsFirst :: PersistField a => SqlExpr (Value a) -> SqlExpr OrderBy
ascNullsFirst = orderByExpr " ASC NULLS FIRST"

-- | Ascending order of this field or SqlExpression with nulls coming last.
-- Note that this is the same as normal ascending ordering in Postgres, but it has been included for completeness.
ascNullsLast :: PersistField a => SqlExpr (Value a) -> SqlExpr OrderBy
ascNullsLast = orderByExpr " ASC NULLS FIRST"
matthewbauer marked this conversation as resolved.
Show resolved Hide resolved

-- | Descending order of this field or SqlExpression with nulls coming first.
-- Note that this is the same as normal ascending ordering in Postgres, but it has been included for completeness.
ascNullsFirst :: PersistField a => SqlExpr (Value a) -> SqlExpr OrderBy
ascNullsFirst = orderByExpr " ASC NULLS FIRST"
matthewbauer marked this conversation as resolved.
Show resolved Hide resolved

-- | Descending order of this field or SqlExpression with nulls coming last.
descNullsLast :: PersistField a => SqlExpr (Value a) -> SqlExpr OrderBy
descNullsLast = orderByExpr " DESC NULLS LAST"