postgresql-simple-0.3.0.0: Mid-Level PostgreSQL client library

Safe HaskellNone

Database.PostgreSQL.Simple.FromField

Synopsis

Documentation

class FromField a whereSource

A type that may be converted from a SQL type.

Methods

fromField :: FieldParser aSource

Convert a SQL value to a Haskell value.

Returns a list of exceptions if the conversion fails. In the case of library instances, this will usually be a single ResultError, but may be a UnicodeException.

Implementations of fromField should not retain any references to the Field nor the ByteString arguments after the result has been evaluated to WHNF. Such a reference causes the entire LibPQ.Result to be retained.

For example, the instance for ByteString uses copy to avoid such a reference, and that using bytestring functions such as drop and takeWhile alone will also trigger this memory leak.

data ResultError Source

Exception thrown if conversion from a SQL value to a Haskell value fails.

Constructors

Incompatible

The SQL and Haskell types are not compatible.

UnexpectedNull

A SQL NULL was encountered when the Haskell type did not permit it.

ConversionFailed

The SQL value could not be parsed, or could not be represented as a valid Haskell value, or an unexpected low-level error occurred (e.g. mismatch between metadata and actual data in a row).

returnError :: forall a err. (Typeable a, Exception err) => (String -> Maybe Oid -> String -> String -> String -> err) -> Field -> String -> Conversion aSource

Given one of the constructors from ResultError, the field, and an errMessage, this fills in the other fields in the exception value and returns it in a 'Left . SomeException' constructor.

data Field Source

A Field represents metadata about a particular field

You don't particularly want to retain these structures for a long period of time, as they will retain the entire query result, not just the field metadata

typename :: Field -> Conversion ByteStringSource

Returns the data type name. This is the preferred way of identifying types that do not have a stable type oid, such as types provided by extensions to PostgreSQL.

More concretely, it returns the typname column associated with the type oid in the pg_type table. First, postgresql-simple will check built-in, static table. If the type oid is not there, postgresql-simple will check a per-connection cache, and then finally query the database's meta-schema.

data TypeInfo Source

Constructors

Basic 
Array 

Instances

name :: Field -> Maybe ByteStringSource

Returns the name of the column. This is often determined by a table definition, but it can be set using an as clause.

tableOid :: Field -> Maybe OidSource

Returns the name of the object id of the table associated with the column, if any. Returns Nothing when there is no such table; for example a computed column does not have a table associated with it. Analogous to libpq's PQftable.

tableColumn :: Field -> IntSource

If the column has a table associated with it, this returns the number off the associated table column. Numbering starts from 0. Analogous to libpq's PQftablecol.

format :: Field -> FormatSource

This returns whether the data was returned in a binary or textual format. Analogous to libpq's PQfformat.

typeOid :: Field -> OidSource

This returns the type oid associated with the column. Analogous to libpq's PQftype.

newtype Oid

Constructors

Oid CUInt 

data Format

Constructors

Text 
Binary