# hasql-postgresql-types[](https://hackage.haskell.org/package/hasql-postgresql-types)[](https://nikita-volkov.github.io/hasql-postgresql-types/)Integration of ["hasql"](https://github.com/nikita-volkov/hasql) with ["postgresql-types"](https://github.com/nikita-volkov/postgresql-types) via the `IsScalar` typeclass from ["postgresql-types-algebra"](https://github.com/nikita-volkov/postgresql-types-algebra).Provides automatic encoder and decoder generation for precise PostgreSQL scalar types.## MotivationThe standard "hasql" codecs use common Haskell types like `Text`, `DiffTime`, `UTCTime`, etc. However these types do not always map precisely to PostgreSQL types. E.g., the PostgreSQL `interval` type carries information about months, years and microseconds, while the Haskell `DiffTime` type only represents a time difference in picoseconds. Such mismatches can lead to data loss or unexpected behavior. The ["postgresql-types"](https://github.com/nikita-volkov/postgresql-types) library addresses such issues by providing precise Haskell representations for PostgreSQL types. This package integrates it with "hasql". It also provides a class-based polymorphic interface for defining "hasql" `Value` codecs.## Usage```haskellimport Hasql.PostgresqlTypes () -- for the instancesimport qualified PostgresqlTypes as Ptimport qualified Hasql.Statement as Statementimport qualified Hasql.Encoders as Encodersimport qualified Hasql.Decoders as Decodersimport qualified Hasql.Mapping.IsScalar as IsScalarmyStatement :: Statement.Statement Pt.Timestamptz [Pt.Timestamptz]myStatement = Statement.preparable sql enc dec where sql = "SELECT $1::timestamptz" enc = Encoders.param (Encoders.nonNullable IsScalar.encoder) dec = Decoders.rowList (Decoders.column (Decoders.nonNullable IsScalar.decoder))```