HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulepostgresql-simple-0.7.0.0Haskell2010

Database.PostgreSQL.Simple.FromRow

The FromRow typeclass, for converting a row of results returned by a SQL query into a more useful Haskell representation.

Predefined instances are provided for tuples containing up to ten elements. The instances for Maybe types return Nothing if all the columns that would have been otherwise consumed are null, otherwise it attempts a regular conversion.

  • 1 type
  • 1 class
  • 3 values
classclass FromRow a where
#

A collection type that can be converted from a sequence of fields. Instances are provided for tuples up to 10 elements and lists of any length.

Note that instances can be defined outside of postgresql-simple, which is often useful. For example, here's an instance for a user-defined pair:

data User = User { name :: String, fileQuota :: Int }

instance FromRow User where
    fromRow = User <$> field <*> field

The number of calls to field must match the number of fields returned in a single row of the query result. Otherwise, a ConversionFailed exception will be thrown.

You can also derive FromRow for your data type using GHC generics, like this:

{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric  #-}

import GHC.Generics (Generic)
import Database.PostgreSQL.Simple (FromRow)

data User = User { name :: String, fileQuota :: Int }
  deriving (Generic, FromRow)

Note that this only works for product types (e.g. records) and does not support sum types or recursive types.

Note that field evaluates its result to WHNF, so the caveats listed in mysql-simple and very early versions of postgresql-simple no longer apply. Instead, look at the caveats associated with user-defined implementations of fromField.

Methods

Instances45FromRow, …
newtypenewtype RowParser a
#
Instances4Monad, Functor, Applicative, Alternative
  • Monad RowParserDefined in postgresql-simple-0.7.0.0 · Database.PostgreSQL.Simple.Internal
  • Functor RowParserDefined in postgresql-simple-0.7.0.0 · Database.PostgreSQL.Simple.Internal
  • Applicative RowParserDefined in postgresql-simple-0.7.0.0 · Database.PostgreSQL.Simple.Internal
  • Alternative RowParserDefined in postgresql-simple-0.7.0.0 · Database.PostgreSQL.Simple.Internal