Safe Haskell | None |
---|---|
Language | Haskell2010 |
Ordering, LIMIT
and OFFSET
- orderBy :: Order a -> Query a -> Query a
- data Order a
- asc :: PGOrd b => (a -> Column b) -> Order a
- desc :: PGOrd b => (a -> Column b) -> Order a
- ascNullsFirst :: PGOrd b => (a -> Column b) -> Order a
- descNullsLast :: PGOrd b => (a -> Column b) -> Order a
- limit :: Int -> Query a -> Query a
- offset :: Int -> Query a -> Query a
- exact :: [Column b] -> (a -> Column b) -> Order a
- class PGOrd a
Order by
orderBy :: Order a -> Query a -> Query a Source #
Order the rows of a Query
according to the Order
.
import Data.Monoid ((<>)) -- Order by the first column ascending. When first columns are equal -- order by second column descending. example ::Query
(Column
PGInt4
,Column
PGText
) ->Query
(Column
PGInt4
,Column
PGText
) example =orderBy
(asc
fst <>desc
snd)
An Order
a
represents a sort order and direction for the elements
of the type a
. Multiple Order
s can be composed with
mappend
or (<>)
from Data.Monoid. If two rows are
equal according to the first Order
in the mappend
, the second is
used, and so on.
Order direction
asc :: PGOrd b => (a -> Column b) -> Order a Source #
Specify an ascending ordering by the given expression. (Any NULLs appear last)
desc :: PGOrd b => (a -> Column b) -> Order a Source #
Specify an descending ordering by the given expression. (Any NULLs appear first)
ascNullsFirst :: PGOrd b => (a -> Column b) -> Order a Source #
Specify an ascending ordering by the given expression. (Any NULLs appear first)
descNullsLast :: PGOrd b => (a -> Column b) -> Order a Source #
Specify an descending ordering by the given expression. (Any NULLs appear last)
Limit and offset
limit :: Int -> Query a -> Query a Source #
Limit the results of the given query to the given maximum number of items.
offset :: Int -> Query a -> Query a Source #
Offset the results of the given query by the given amount, skipping that many result rows.
Exact ordering
exact :: [Column b] -> (a -> Column b) -> Order a Source #
Order the results of a given query exactly, as determined by the given list of input columns. Note that this list does not have to contain an entry for every result in your query: you may exactly order only a subset of results, if you wish. Rows that are not ordered according to the input list are returned after the ordered results, in the usual order the database would return them (e.g. sorted by primary key). Exactly-ordered results always come first in a result set. Entries in the input list that are not present in result of a query are ignored.
Other
Typeclass for Postgres types which support ordering operations.