HORIZON HASKELLDocslts/ghc-10.0.x8fef28d2026-11-02Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8fef28d · 2026-11-02

Moduleopaleye-0.10.8.0Haskell2010

Opaleye.Order

ORDER BY, LIMIT, OFFSET and DISTINCT ON

Contents
  1. Order by
  2. Order direction
  3. Limit and offset
  4. Distinct on
  5. Exact ordering
  6. Other
  7. Explicit versions
  8. Deprecated
Synopsis
  • Packageopaleye-0.10.8.0
  • Exports20
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceOrder.hs

Order by

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

Limit and offset

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

Distinct on

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

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

classclass SqlOrd a

Typeclass for Postgres types which support ordering operations.

Instances15SqlOrd, …

Explicit versions

Deprecated