HORIZON HASKELLDocslts/ghc-10.0.x8c2f8e82026-10-19Search names, modules, packages, or :: a typeCtrl K

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8c2f8e8 · 2026-10-19

Moduleopaleye-0.10.8.0Haskell2010

Opaleye.Order

ORDER BY, LIMIT, OFFSET and DISTINCT ON

  • 1 type
  • 1 class
  • 18 values
  • Packageopaleye-0.10.8.0
  • Exports20
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceOrder.hs

Order by

2 declarations
newtypenewtype Order a
#

An Order a represents a sort order and direction for the elements of the type a. Multiple Orders 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.

Instances5Contravariant, Decidable, Divisible, Semigroup, Monoid

Order direction

6 declarations
valueasc :: SqlOrd b => (a -> Field b) -> Order a
#

Specify an ascending ordering by the given expression.

valuedesc :: SqlOrd b => (a -> Field b) -> Order a
#

Specify an descending ordering by the given expression.

Limit and offset

4 declarations
valuelimit :: Int -> Select a -> Select a
#

Limit the results of the given Select to the given maximum number of items.

WARNING: If you're planning on using limit/offset together please use offset before you use limit, e.g.:

limit 10 (offset 50 yourSelect)

This is because Opaleye applies OFFSET and LIMIT to the SELECT separately. The result of the Select given above is the following, which will return 10 rows after skipping the first 50 (probably what you want).

SELECT * FROM (SELECT * FROM yourTable OFFSET 50) LIMIT 10

However, reversing the order of the limit/offset will result in the following, which will result in no rows being returned (probably not what you want).

SELECT * FROM (SELECT * FROM yourTable LIMIT 10) OFFSET 50
valueoffset :: Int -> Select a -> Select a
#

Offset the results of the given Select by the given amount, skipping that many result rows.

WARNING: Please read the documentation of limit before combining offset with limit.

Distinct on

2 declarations
valuedistinctOn :: Default Unpackspec b b => (a -> b) -> Select a -> Select a
#

Keep a row from each set where the given function returns the same result. No ordering is guaranteed. Multiple fields may be distinguished by projecting out tuples of Field_s. Use distinctOnBy to control how the rows are chosen.

valuedistinctOnBy
  1. :: Default Unpackspec b b
  2. => a -> b
  3. -> Order a
  4. -> Select a
  5. -> Select a
#

Keep the row from each set where the given function returns the same result. The row is chosen according to which comes first by the supplied ordering. However, no output ordering is guaranteed. Multiple fields may be distinguished by projecting out tuples of Field_s.

Exact ordering

1 declaration
valueexact :: [Field_ n b] -> (a -> Field_ n b) -> Order a
#

Order the results of a given query exactly, as determined by the given list of input fields. 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

1 declaration
classclass SqlOrd a
#

Typeclass for Postgres types which support ordering operations.

Instances15SqlOrd, …

Explicit versions

2 declarations

Deprecated

2 declarations