    {-# LANGUAGE CPP, DeriveDataTypeable, DeriveFunctor, GeneralizedNewtypeDeriving #-}

    ------------------------------------------------------------------------------
    -- |
    -- Module:      Database.PostgreSQL.Simple.Types
    -- Copyright:   (c) 2011 MailRank, Inc.
    --              (c) 2011-2012 Leon P Smith
    -- License:     BSD3
    -- Maintainer:  Leon P Smith <leon@melding-monads.com>
    -- Stability:   experimental
    --
    -- Basic types.
    --
    ------------------------------------------------------------------------------

    module Database.PostgreSQL.Simple.Types
        (
          Null(..)
        , Default(..)
        , Only(..)
        , In(..)
        , Binary(..)
        , Identifier(..)
        , QualifiedIdentifier(..)
        , Query(..)
        , Oid(..)
        , (:.)(..)
        , Savepoint(..)
        , PGArray(..)
        , Values(..)
        ) where

    import           Control.Arrow (first)
    import           Data.ByteString (ByteString)
    import           Data.Hashable (Hashable(hashWithSalt))
    import           Data.Foldable (toList)
    import           Data.Monoid (Monoid(..))
    import           Data.Semigroup
    import           Data.String (IsString(..))
    import           Data.Typeable (Typeable)
    import           Data.ByteString.Builder ( stringUtf8 )
    import qualified Data.ByteString as B
    import           Data.Text (Text)
    import qualified Data.Text as T
    import           Data.Tuple.Only (Only(..))
    import           Database.PostgreSQL.LibPQ (Oid(..))
    import           Database.PostgreSQL.Simple.Compat (toByteString)

    -- | A placeholder for the SQL @NULL@ value.
    data Null = Null
              deriving (ReadPrec [Null]
    ReadPrec Null
    Int -> ReadS Null
    ReadS [Null]
    (Int -> ReadS Null)
    -> ReadS [Null] -> ReadPrec Null -> ReadPrec [Null] -> Read Null
    forall a.
    (Int -> ReadS a)
    -> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
    $creadsPrec :: Int -> ReadS Null
    readsPrec :: Int -> ReadS Null
    $creadList :: ReadS [Null]
    readList :: ReadS [Null]
    $creadPrec :: ReadPrec Null
    readPrec :: ReadPrec Null
    $creadListPrec :: ReadPrec [Null]
    readListPrec :: ReadPrec [Null]
    Read, Int -> Null -> ShowS
    [Null] -> ShowS
    Null -> String
    (Int -> Null -> ShowS)
    -> (Null -> String) -> ([Null] -> ShowS) -> Show Null
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> Null -> ShowS
    showsPrec :: Int -> Null -> ShowS
    $cshow :: Null -> String
    show :: Null -> String
    $cshowList :: [Null] -> ShowS
    showList :: [Null] -> ShowS
    Show, Typeable)

    -- | A placeholder for the PostgreSQL @DEFAULT@ value.
    data Default = Default
               deriving (ReadPrec [Default]
    ReadPrec Default
    Int -> ReadS Default
    ReadS [Default]
    (Int -> ReadS Default)
    -> ReadS [Default]
    -> ReadPrec Default
    -> ReadPrec [Default]
    -> Read Default
    forall a.
    (Int -> ReadS a)
    -> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
    $creadsPrec :: Int -> ReadS Default
    readsPrec :: Int -> ReadS Default
    $creadList :: ReadS [Default]
    readList :: ReadS [Default]
    $creadPrec :: ReadPrec Default
    readPrec :: ReadPrec Default
    $creadListPrec :: ReadPrec [Default]
    readListPrec :: ReadPrec [Default]
    Read, Int -> Default -> ShowS
    [Default] -> ShowS
    Default -> String
    (Int -> Default -> ShowS)
    -> (Default -> String) -> ([Default] -> ShowS) -> Show Default
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> Default -> ShowS
    showsPrec :: Int -> Default -> ShowS
    $cshow :: Default -> String
    show :: Default -> String
    $cshowList :: [Default] -> ShowS
    showList :: [Default] -> ShowS
    Show, Typeable)

    -- | A query string. This type is intended to make it difficult to
    -- construct a SQL query by concatenating string fragments, as that is
    -- an extremely common way to accidentally introduce SQL injection
    -- vulnerabilities into an application.
    --
    -- This type is an instance of 'IsString', so the easiest way to
    -- construct a query is to enable the @OverloadedStrings@ language
    -- extension and then simply write the query in double quotes.
    --
    -- > {-# LANGUAGE OverloadedStrings #-}
    -- >
    -- > import Database.PostgreSQL.Simple
    -- >
    -- > q :: Query
    -- > q = "select ?"
    --
    -- The underlying type is a 'ByteString', and literal Haskell strings
    -- that contain Unicode characters will be correctly transformed to
    -- UTF-8.
    newtype Query = Query {
          Query -> ByteString
    fromQuery :: ByteString
        } deriving (Query -> Query -> Bool
    (Query -> Query -> Bool) -> (Query -> Query -> Bool) -> Eq Query
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: Query -> Query -> Bool
    == :: Query -> Query -> Bool
    $c/= :: Query -> Query -> Bool
    /= :: Query -> Query -> Bool
    Eq, Eq Query
    Eq Query =>
    (Query -> Query -> Ordering)
    -> (Query -> Query -> Bool)
    -> (Query -> Query -> Bool)
    -> (Query -> Query -> Bool)
    -> (Query -> Query -> Bool)
    -> (Query -> Query -> Query)
    -> (Query -> Query -> Query)
    -> Ord Query
    Query -> Query -> Bool
    Query -> Query -> Ordering
    Query -> Query -> Query
    forall a.
    Eq a =>
    (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    $ccompare :: Query -> Query -> Ordering
    compare :: Query -> Query -> Ordering
    $c< :: Query -> Query -> Bool
    < :: Query -> Query -> Bool
    $c<= :: Query -> Query -> Bool
    <= :: Query -> Query -> Bool
    $c> :: Query -> Query -> Bool
    > :: Query -> Query -> Bool
    $c>= :: Query -> Query -> Bool
    >= :: Query -> Query -> Bool
    $cmax :: Query -> Query -> Query
    max :: Query -> Query -> Query
    $cmin :: Query -> Query -> Query
    min :: Query -> Query -> Query
    Ord, Typeable)

    instance Show Query where
        show :: Query -> String
    show = ByteString -> String
    forall a. Show a => a -> String
    show (ByteString -> String) -> (Query -> ByteString) -> Query -> String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Query -> ByteString
    fromQuery

    instance Read Query where
        readsPrec :: Int -> ReadS Query
    readsPrec Int
    i = ((ByteString, String) -> (Query, String))
    -> [(ByteString, String)] -> [(Query, String)]
    forall a b. (a -> b) -> [a] -> [b]
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap ((ByteString -> Query) -> (ByteString, String) -> (Query, String)
    forall b c d. (b -> c) -> (b, d) -> (c, d)
    forall (a :: * -> * -> *) b c d.
    Arrow a =>
    a b c -> a (b, d) (c, d)
    first ByteString -> Query
    Query) ([(ByteString, String)] -> [(Query, String)])
    -> (String -> [(ByteString, String)]) -> ReadS Query
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Int -> String -> [(ByteString, String)]
    forall a. Read a => Int -> ReadS a
    readsPrec Int
    i

    instance IsString Query where
        fromString :: String -> Query
    fromString = ByteString -> Query
    Query (ByteString -> Query) -> (String -> ByteString) -> String -> Query
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Builder -> ByteString
    toByteString (Builder -> ByteString)
    -> (String -> Builder) -> String -> ByteString
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . String -> Builder
    stringUtf8

    instance Semigroup Query where
        Query ByteString
    a <> :: Query -> Query -> Query
    <> Query ByteString
    b = ByteString -> Query
    Query (ByteString -> ByteString -> ByteString
    B.append ByteString
    a ByteString
    b)
        {-# INLINE (<>) #-}
        sconcat :: NonEmpty Query -> Query
    sconcat NonEmpty Query
    xs = ByteString -> Query
    Query ([ByteString] -> ByteString
    B.concat ([ByteString] -> ByteString) -> [ByteString] -> ByteString
    forall a b. (a -> b) -> a -> b
    $ (Query -> ByteString) -> [Query] -> [ByteString]
    forall a b. (a -> b) -> [a] -> [b]
    map Query -> ByteString
    fromQuery ([Query] -> [ByteString]) -> [Query] -> [ByteString]
    forall a b. (a -> b) -> a -> b
    $ NonEmpty Query -> [Query]
    forall a. NonEmpty a -> [a]
    forall (t :: * -> *) a. Foldable t => t a -> [a]
    toList NonEmpty Query
    xs)

    instance Monoid Query where
        mempty :: Query
    mempty = ByteString -> Query
    Query ByteString
    B.empty

    -- | Wrap a list of values for use in an @IN@ clause.  Replaces a
    -- single \"@?@\" character with a parenthesized list of rendered
    -- values.
    --
    -- Example:
    --
    -- > query c "select * from whatever where id in ?" (Only (In [3,4,5]))
    --
    -- Note that @In []@ expands to @(null)@, which works as expected in
    -- the query above, but evaluates to the logical null value on every
    -- row instead of @TRUE@.  This means that changing the query above
    -- to @... id NOT in ?@ and supplying the empty list as the parameter
    -- returns zero rows, instead of all of them as one would expect.
    --
    -- Since postgresql doesn't seem to provide a syntax for actually specifying
    -- an empty list,  which could solve this completely,  there are two
    -- workarounds particularly worth mentioning,  namely:
    --
    -- 1.  Use postgresql-simple's 'Values' type instead,  which can handle the
    --     empty case correctly.  Note however that while specifying the
    --     postgresql type @"int4"@ is mandatory in the empty case,  specifying
    --     the haskell type @Values (Only Int)@ would not normally be needed in
    --     realistic use cases.
    --
    --     > query c "select * from whatever where id not in ?"
    --     >         (Only (Values ["int4"] [] :: Values (Only Int)))
    --
    --
    -- 2.  Use sql's @COALESCE@ operator to turn a logical @null@ into the correct
    --     boolean.  Note however that the correct boolean depends on the use
    --     case:
    --
    --     > query c "select * from whatever where coalesce(id NOT in ?, TRUE)"
    --     >         (Only (In [] :: In [Int]))
    --
    --     > query c "select * from whatever where coalesce(id IN ?, FALSE)"
    --     >         (Only (In [] :: In [Int]))
    --
    --     Note that at as of PostgreSQL 9.4,  the query planner cannot see inside
    --     the @COALESCE@ operator,  so if you have an index on @id@ then you
    --     probably don't want to write the last example with @COALESCE@,  which
    --     would result in a table scan.   There are further caveats if @id@ can
    --     be null or you want null treated sensibly as a component of @IN@ or
    --     @NOT IN@.

    newtype In a = In a
        deriving (In a -> In a -> Bool
    (In a -> In a -> Bool) -> (In a -> In a -> Bool) -> Eq (In a)
    forall a. Eq a => In a -> In a -> Bool
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: forall a. Eq a => In a -> In a -> Bool
    == :: In a -> In a -> Bool
    $c/= :: forall a. Eq a => In a -> In a -> Bool
    /= :: In a -> In a -> Bool
    Eq, Eq (In a)
    Eq (In a) =>
    (In a -> In a -> Ordering)
    -> (In a -> In a -> Bool)
    -> (In a -> In a -> Bool)
    -> (In a -> In a -> Bool)
    -> (In a -> In a -> Bool)
    -> (In a -> In a -> In a)
    -> (In a -> In a -> In a)
    -> Ord (In a)
    In a -> In a -> Bool
    In a -> In a -> Ordering
    In a -> In a -> In a
    forall a.
    Eq a =>
    (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    forall a. Ord a => Eq (In a)
    forall a. Ord a => In a -> In a -> Bool
    forall a. Ord a => In a -> In a -> Ordering
    forall a. Ord a => In a -> In a -> In a
    $ccompare :: forall a. Ord a => In a -> In a -> Ordering
    compare :: In a -> In a -> Ordering
    $c< :: forall a. Ord a => In a -> In a -> Bool
    < :: In a -> In a -> Bool
    $c<= :: forall a. Ord a => In a -> In a -> Bool
    <= :: In a -> In a -> Bool
    $c> :: forall a. Ord a => In a -> In a -> Bool
    > :: In a -> In a -> Bool
    $c>= :: forall a. Ord a => In a -> In a -> Bool
    >= :: In a -> In a -> Bool
    $cmax :: forall a. Ord a => In a -> In a -> In a
    max :: In a -> In a -> In a
    $cmin :: forall a. Ord a => In a -> In a -> In a
    min :: In a -> In a -> In a
    Ord, ReadPrec [In a]
    ReadPrec (In a)
    Int -> ReadS (In a)
    ReadS [In a]
    (Int -> ReadS (In a))
    -> ReadS [In a]
    -> ReadPrec (In a)
    -> ReadPrec [In a]
    -> Read (In a)
    forall a. Read a => ReadPrec [In a]
    forall a. Read a => ReadPrec (In a)
    forall a. Read a => Int -> ReadS (In a)
    forall a. Read a => ReadS [In a]
    forall a.
    (Int -> ReadS a)
    -> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
    $creadsPrec :: forall a. Read a => Int -> ReadS (In a)
    readsPrec :: Int -> ReadS (In a)
    $creadList :: forall a. Read a => ReadS [In a]
    readList :: ReadS [In a]
    $creadPrec :: forall a. Read a => ReadPrec (In a)
    readPrec :: ReadPrec (In a)
    $creadListPrec :: forall a. Read a => ReadPrec [In a]
    readListPrec :: ReadPrec [In a]
    Read, Int -> In a -> ShowS
    [In a] -> ShowS
    In a -> String
    (Int -> In a -> ShowS)
    -> (In a -> String) -> ([In a] -> ShowS) -> Show (In a)
    forall a. Show a => Int -> In a -> ShowS
    forall a. Show a => [In a] -> ShowS
    forall a. Show a => In a -> String
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: forall a. Show a => Int -> In a -> ShowS
    showsPrec :: Int -> In a -> ShowS
    $cshow :: forall a. Show a => In a -> String
    show :: In a -> String
    $cshowList :: forall a. Show a => [In a] -> ShowS
    showList :: [In a] -> ShowS
    Show, Typeable, (forall a b. (a -> b) -> In a -> In b)
    -> (forall a b. a -> In b -> In a) -> Functor In
    forall a b. a -> In b -> In a
    forall a b. (a -> b) -> In a -> In b
    forall (f :: * -> *).
    (forall a b. (a -> b) -> f a -> f b)
    -> (forall a b. a -> f b -> f a) -> Functor f
    $cfmap :: forall a b. (a -> b) -> In a -> In b
    fmap :: forall a b. (a -> b) -> In a -> In b
    $c<$ :: forall a b. a -> In b -> In a
    <$ :: forall a b. a -> In b -> In a
    Functor)

    -- | Wrap binary data for use as a @bytea@ value.
    newtype Binary a = Binary {forall a. Binary a -> a
    fromBinary :: a}
        deriving (Binary a -> Binary a -> Bool
    (Binary a -> Binary a -> Bool)
    -> (Binary a -> Binary a -> Bool) -> Eq (Binary a)
    forall a. Eq a => Binary a -> Binary a -> Bool
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: forall a. Eq a => Binary a -> Binary a -> Bool
    == :: Binary a -> Binary a -> Bool
    $c/= :: forall a. Eq a => Binary a -> Binary a -> Bool
    /= :: Binary a -> Binary a -> Bool
    Eq, Eq (Binary a)
    Eq (Binary a) =>
    (Binary a -> Binary a -> Ordering)
    -> (Binary a -> Binary a -> Bool)
    -> (Binary a -> Binary a -> Bool)
    -> (Binary a -> Binary a -> Bool)
    -> (Binary a -> Binary a -> Bool)
    -> (Binary a -> Binary a -> Binary a)
    -> (Binary a -> Binary a -> Binary a)
    -> Ord (Binary a)
    Binary a -> Binary a -> Bool
    Binary a -> Binary a -> Ordering
    Binary a -> Binary a -> Binary a
    forall a.
    Eq a =>
    (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    forall a. Ord a => Eq (Binary a)
    forall a. Ord a => Binary a -> Binary a -> Bool
    forall a. Ord a => Binary a -> Binary a -> Ordering
    forall a. Ord a => Binary a -> Binary a -> Binary a
    $ccompare :: forall a. Ord a => Binary a -> Binary a -> Ordering
    compare :: Binary a -> Binary a -> Ordering
    $c< :: forall a. Ord a => Binary a -> Binary a -> Bool
    < :: Binary a -> Binary a -> Bool
    $c<= :: forall a. Ord a => Binary a -> Binary a -> Bool
    <= :: Binary a -> Binary a -> Bool
    $c> :: forall a. Ord a => Binary a -> Binary a -> Bool
    > :: Binary a -> Binary a -> Bool
    $c>= :: forall a. Ord a => Binary a -> Binary a -> Bool
    >= :: Binary a -> Binary a -> Bool
    $cmax :: forall a. Ord a => Binary a -> Binary a -> Binary a
    max :: Binary a -> Binary a -> Binary a
    $cmin :: forall a. Ord a => Binary a -> Binary a -> Binary a
    min :: Binary a -> Binary a -> Binary a
    Ord, ReadPrec [Binary a]
    ReadPrec (Binary a)
    Int -> ReadS (Binary a)
    ReadS [Binary a]
    (Int -> ReadS (Binary a))
    -> ReadS [Binary a]
    -> ReadPrec (Binary a)
    -> ReadPrec [Binary a]
    -> Read (Binary a)
    forall a. Read a => ReadPrec [Binary a]
    forall a. Read a => ReadPrec (Binary a)
    forall a. Read a => Int -> ReadS (Binary a)
    forall a. Read a => ReadS [Binary a]
    forall a.
    (Int -> ReadS a)
    -> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
    $creadsPrec :: forall a. Read a => Int -> ReadS (Binary a)
    readsPrec :: Int -> ReadS (Binary a)
    $creadList :: forall a. Read a => ReadS [Binary a]
    readList :: ReadS [Binary a]
    $creadPrec :: forall a. Read a => ReadPrec (Binary a)
    readPrec :: ReadPrec (Binary a)
    $creadListPrec :: forall a. Read a => ReadPrec [Binary a]
    readListPrec :: ReadPrec [Binary a]
    Read, Int -> Binary a -> ShowS
    [Binary a] -> ShowS
    Binary a -> String
    (Int -> Binary a -> ShowS)
    -> (Binary a -> String) -> ([Binary a] -> ShowS) -> Show (Binary a)
    forall a. Show a => Int -> Binary a -> ShowS
    forall a. Show a => [Binary a] -> ShowS
    forall a. Show a => Binary a -> String
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: forall a. Show a => Int -> Binary a -> ShowS
    showsPrec :: Int -> Binary a -> ShowS
    $cshow :: forall a. Show a => Binary a -> String
    show :: Binary a -> String
    $cshowList :: forall a. Show a => [Binary a] -> ShowS
    showList :: [Binary a] -> ShowS
    Show, Typeable, (forall a b. (a -> b) -> Binary a -> Binary b)
    -> (forall a b. a -> Binary b -> Binary a) -> Functor Binary
    forall a b. a -> Binary b -> Binary a
    forall a b. (a -> b) -> Binary a -> Binary b
    forall (f :: * -> *).
    (forall a b. (a -> b) -> f a -> f b)
    -> (forall a b. a -> f b -> f a) -> Functor f
    $cfmap :: forall a b. (a -> b) -> Binary a -> Binary b
    fmap :: forall a b. (a -> b) -> Binary a -> Binary b
    $c<$ :: forall a b. a -> Binary b -> Binary a
    <$ :: forall a b. a -> Binary b -> Binary a
    Functor)

    -- | Wrap text for use as sql identifier, i.e. a table or column name.
    newtype Identifier = Identifier {Identifier -> Text
    fromIdentifier :: Text}
        deriving (Identifier -> Identifier -> Bool
    (Identifier -> Identifier -> Bool)
    -> (Identifier -> Identifier -> Bool) -> Eq Identifier
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: Identifier -> Identifier -> Bool
    == :: Identifier -> Identifier -> Bool
    $c/= :: Identifier -> Identifier -> Bool
    /= :: Identifier -> Identifier -> Bool
    Eq, Eq Identifier
    Eq Identifier =>
    (Identifier -> Identifier -> Ordering)
    -> (Identifier -> Identifier -> Bool)
    -> (Identifier -> Identifier -> Bool)
    -> (Identifier -> Identifier -> Bool)
    -> (Identifier -> Identifier -> Bool)
    -> (Identifier -> Identifier -> Identifier)
    -> (Identifier -> Identifier -> Identifier)
    -> Ord Identifier
    Identifier -> Identifier -> Bool
    Identifier -> Identifier -> Ordering
    Identifier -> Identifier -> Identifier
    forall a.
    Eq a =>
    (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    $ccompare :: Identifier -> Identifier -> Ordering
    compare :: Identifier -> Identifier -> Ordering
    $c< :: Identifier -> Identifier -> Bool
    < :: Identifier -> Identifier -> Bool
    $c<= :: Identifier -> Identifier -> Bool
    <= :: Identifier -> Identifier -> Bool
    $c> :: Identifier -> Identifier -> Bool
    > :: Identifier -> Identifier -> Bool
    $c>= :: Identifier -> Identifier -> Bool
    >= :: Identifier -> Identifier -> Bool
    $cmax :: Identifier -> Identifier -> Identifier
    max :: Identifier -> Identifier -> Identifier
    $cmin :: Identifier -> Identifier -> Identifier
    min :: Identifier -> Identifier -> Identifier
    Ord, ReadPrec [Identifier]
    ReadPrec Identifier
    Int -> ReadS Identifier
    ReadS [Identifier]
    (Int -> ReadS Identifier)
    -> ReadS [Identifier]
    -> ReadPrec Identifier
    -> ReadPrec [Identifier]
    -> Read Identifier
    forall a.
    (Int -> ReadS a)
    -> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
    $creadsPrec :: Int -> ReadS Identifier
    readsPrec :: Int -> ReadS Identifier
    $creadList :: ReadS [Identifier]
    readList :: ReadS [Identifier]
    $creadPrec :: ReadPrec Identifier
    readPrec :: ReadPrec Identifier
    $creadListPrec :: ReadPrec [Identifier]
    readListPrec :: ReadPrec [Identifier]
    Read, Int -> Identifier -> ShowS
    [Identifier] -> ShowS
    Identifier -> String
    (Int -> Identifier -> ShowS)
    -> (Identifier -> String)
    -> ([Identifier] -> ShowS)
    -> Show Identifier
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> Identifier -> ShowS
    showsPrec :: Int -> Identifier -> ShowS
    $cshow :: Identifier -> String
    show :: Identifier -> String
    $cshowList :: [Identifier] -> ShowS
    showList :: [Identifier] -> ShowS
    Show, Typeable, String -> Identifier
    (String -> Identifier) -> IsString Identifier
    forall a. (String -> a) -> IsString a
    $cfromString :: String -> Identifier
    fromString :: String -> Identifier
    IsString)

    instance Hashable Identifier where
        hashWithSalt :: Int -> Identifier -> Int
    hashWithSalt Int
    i (Identifier Text
    t) = Int -> Text -> Int
    forall a. Hashable a => Int -> a -> Int
    hashWithSalt Int
    i Text
    t

    -- | Wrap text for use as (maybe) qualified identifier, i.e. a table
    -- with schema, or column with table.
    data QualifiedIdentifier = QualifiedIdentifier (Maybe Text) Text
        deriving (QualifiedIdentifier -> QualifiedIdentifier -> Bool
    (QualifiedIdentifier -> QualifiedIdentifier -> Bool)
    -> (QualifiedIdentifier -> QualifiedIdentifier -> Bool)
    -> Eq QualifiedIdentifier
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: QualifiedIdentifier -> QualifiedIdentifier -> Bool
    == :: QualifiedIdentifier -> QualifiedIdentifier -> Bool
    $c/= :: QualifiedIdentifier -> QualifiedIdentifier -> Bool
    /= :: QualifiedIdentifier -> QualifiedIdentifier -> Bool
    Eq, Eq QualifiedIdentifier
    Eq QualifiedIdentifier =>
    (QualifiedIdentifier -> QualifiedIdentifier -> Ordering)
    -> (QualifiedIdentifier -> QualifiedIdentifier -> Bool)
    -> (QualifiedIdentifier -> QualifiedIdentifier -> Bool)
    -> (QualifiedIdentifier -> QualifiedIdentifier -> Bool)
    -> (QualifiedIdentifier -> QualifiedIdentifier -> Bool)
    -> (QualifiedIdentifier
        -> QualifiedIdentifier -> QualifiedIdentifier)
    -> (QualifiedIdentifier
        -> QualifiedIdentifier -> QualifiedIdentifier)
    -> Ord QualifiedIdentifier
    QualifiedIdentifier -> QualifiedIdentifier -> Bool
    QualifiedIdentifier -> QualifiedIdentifier -> Ordering
    QualifiedIdentifier -> QualifiedIdentifier -> QualifiedIdentifier
    forall a.
    Eq a =>
    (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    $ccompare :: QualifiedIdentifier -> QualifiedIdentifier -> Ordering
    compare :: QualifiedIdentifier -> QualifiedIdentifier -> Ordering
    $c< :: QualifiedIdentifier -> QualifiedIdentifier -> Bool
    < :: QualifiedIdentifier -> QualifiedIdentifier -> Bool
    $c<= :: QualifiedIdentifier -> QualifiedIdentifier -> Bool
    <= :: QualifiedIdentifier -> QualifiedIdentifier -> Bool
    $c> :: QualifiedIdentifier -> QualifiedIdentifier -> Bool
    > :: QualifiedIdentifier -> QualifiedIdentifier -> Bool
    $c>= :: QualifiedIdentifier -> QualifiedIdentifier -> Bool
    >= :: QualifiedIdentifier -> QualifiedIdentifier -> Bool
    $cmax :: QualifiedIdentifier -> QualifiedIdentifier -> QualifiedIdentifier
    max :: QualifiedIdentifier -> QualifiedIdentifier -> QualifiedIdentifier
    $cmin :: QualifiedIdentifier -> QualifiedIdentifier -> QualifiedIdentifier
    min :: QualifiedIdentifier -> QualifiedIdentifier -> QualifiedIdentifier
    Ord, ReadPrec [QualifiedIdentifier]
    ReadPrec QualifiedIdentifier
    Int -> ReadS QualifiedIdentifier
    ReadS [QualifiedIdentifier]
    (Int -> ReadS QualifiedIdentifier)
    -> ReadS [QualifiedIdentifier]
    -> ReadPrec QualifiedIdentifier
    -> ReadPrec [QualifiedIdentifier]
    -> Read QualifiedIdentifier
    forall a.
    (Int -> ReadS a)
    -> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
    $creadsPrec :: Int -> ReadS QualifiedIdentifier
    readsPrec :: Int -> ReadS QualifiedIdentifier
    $creadList :: ReadS [QualifiedIdentifier]
    readList :: ReadS [QualifiedIdentifier]
    $creadPrec :: ReadPrec QualifiedIdentifier
    readPrec :: ReadPrec QualifiedIdentifier
    $creadListPrec :: ReadPrec [QualifiedIdentifier]
    readListPrec :: ReadPrec [QualifiedIdentifier]
    Read, Int -> QualifiedIdentifier -> ShowS
    [QualifiedIdentifier] -> ShowS
    QualifiedIdentifier -> String
    (Int -> QualifiedIdentifier -> ShowS)
    -> (QualifiedIdentifier -> String)
    -> ([QualifiedIdentifier] -> ShowS)
    -> Show QualifiedIdentifier
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> QualifiedIdentifier -> ShowS
    showsPrec :: Int -> QualifiedIdentifier -> ShowS
    $cshow :: QualifiedIdentifier -> String
    show :: QualifiedIdentifier -> String
    $cshowList :: [QualifiedIdentifier] -> ShowS
    showList :: [QualifiedIdentifier] -> ShowS
    Show, Typeable)

    instance Hashable QualifiedIdentifier where
        hashWithSalt :: Int -> QualifiedIdentifier -> Int
    hashWithSalt Int
    i (QualifiedIdentifier Maybe Text
    q Text
    t) = Int -> (Maybe Text, Text) -> Int
    forall a. Hashable a => Int -> a -> Int
    hashWithSalt Int
    i (Maybe Text
    q, Text
    t)

    -- | @\"foo.bar\"@ will get turned into
    -- @QualifiedIdentifier (Just \"foo\") \"bar\"@,  while @\"foo\"@ will get
    -- turned into @QualifiedIdentifier Nothing \"foo\"@.   Note this instance
    -- is for convenience,  and does not match postgres syntax.   It
    -- only examines the first period character,  and thus cannot be used if the
    -- qualifying identifier contains a period for example.

    instance IsString QualifiedIdentifier where
        fromString :: String -> QualifiedIdentifier
    fromString String
    str = let (Text
    x,Text
    y) = (Char -> Bool) -> Text -> (Text, Text)
    T.break (Char -> Char -> Bool
    forall a. Eq a => a -> a -> Bool
    == Char
    '.') (String -> Text
    forall a. IsString a => String -> a
    fromString String
    str)
                          in if Text -> Bool
    T.null Text
    y
                             then Maybe Text -> Text -> QualifiedIdentifier
    QualifiedIdentifier Maybe Text
    forall a. Maybe a
    Nothing Text
    x
                             else Maybe Text -> Text -> QualifiedIdentifier
    QualifiedIdentifier (Text -> Maybe Text
    forall a. a -> Maybe a
    Just Text
    x) (HasCallStack => Text -> Text
    Text -> Text
    T.tail Text
    y)

    -- | Wrap a list for use as a PostgreSQL array.
    newtype PGArray a = PGArray {forall a. PGArray a -> [a]
    fromPGArray :: [a]}
        deriving (PGArray a -> PGArray a -> Bool
    (PGArray a -> PGArray a -> Bool)
    -> (PGArray a -> PGArray a -> Bool) -> Eq (PGArray a)
    forall a. Eq a => PGArray a -> PGArray a -> Bool
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: forall a. Eq a => PGArray a -> PGArray a -> Bool
    == :: PGArray a -> PGArray a -> Bool
    $c/= :: forall a. Eq a => PGArray a -> PGArray a -> Bool
    /= :: PGArray a -> PGArray a -> Bool
    Eq, Eq (PGArray a)
    Eq (PGArray a) =>
    (PGArray a -> PGArray a -> Ordering)
    -> (PGArray a -> PGArray a -> Bool)
    -> (PGArray a -> PGArray a -> Bool)
    -> (PGArray a -> PGArray a -> Bool)
    -> (PGArray a -> PGArray a -> Bool)
    -> (PGArray a -> PGArray a -> PGArray a)
    -> (PGArray a -> PGArray a -> PGArray a)
    -> Ord (PGArray a)
    PGArray a -> PGArray a -> Bool
    PGArray a -> PGArray a -> Ordering
    PGArray a -> PGArray a -> PGArray a
    forall a.
    Eq a =>
    (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    forall a. Ord a => Eq (PGArray a)
    forall a. Ord a => PGArray a -> PGArray a -> Bool
    forall a. Ord a => PGArray a -> PGArray a -> Ordering
    forall a. Ord a => PGArray a -> PGArray a -> PGArray a
    $ccompare :: forall a. Ord a => PGArray a -> PGArray a -> Ordering
    compare :: PGArray a -> PGArray a -> Ordering
    $c< :: forall a. Ord a => PGArray a -> PGArray a -> Bool
    < :: PGArray a -> PGArray a -> Bool
    $c<= :: forall a. Ord a => PGArray a -> PGArray a -> Bool
    <= :: PGArray a -> PGArray a -> Bool
    $c> :: forall a. Ord a => PGArray a -> PGArray a -> Bool
    > :: PGArray a -> PGArray a -> Bool
    $c>= :: forall a. Ord a => PGArray a -> PGArray a -> Bool
    >= :: PGArray a -> PGArray a -> Bool
    $cmax :: forall a. Ord a => PGArray a -> PGArray a -> PGArray a
    max :: PGArray a -> PGArray a -> PGArray a
    $cmin :: forall a. Ord a => PGArray a -> PGArray a -> PGArray a
    min :: PGArray a -> PGArray a -> PGArray a
    Ord, ReadPrec [PGArray a]
    ReadPrec (PGArray a)
    Int -> ReadS (PGArray a)
    ReadS [PGArray a]
    (Int -> ReadS (PGArray a))
    -> ReadS [PGArray a]
    -> ReadPrec (PGArray a)
    -> ReadPrec [PGArray a]
    -> Read (PGArray a)
    forall a. Read a => ReadPrec [PGArray a]
    forall a. Read a => ReadPrec (PGArray a)
    forall a. Read a => Int -> ReadS (PGArray a)
    forall a. Read a => ReadS [PGArray a]
    forall a.
    (Int -> ReadS a)
    -> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
    $creadsPrec :: forall a. Read a => Int -> ReadS (PGArray a)
    readsPrec :: Int -> ReadS (PGArray a)
    $creadList :: forall a. Read a => ReadS [PGArray a]
    readList :: ReadS [PGArray a]
    $creadPrec :: forall a. Read a => ReadPrec (PGArray a)
    readPrec :: ReadPrec (PGArray a)
    $creadListPrec :: forall a. Read a => ReadPrec [PGArray a]
    readListPrec :: ReadPrec [PGArray a]
    Read, Int -> PGArray a -> ShowS
    [PGArray a] -> ShowS
    PGArray a -> String
    (Int -> PGArray a -> ShowS)
    -> (PGArray a -> String)
    -> ([PGArray a] -> ShowS)
    -> Show (PGArray a)
    forall a. Show a => Int -> PGArray a -> ShowS
    forall a. Show a => [PGArray a] -> ShowS
    forall a. Show a => PGArray a -> String
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: forall a. Show a => Int -> PGArray a -> ShowS
    showsPrec :: Int -> PGArray a -> ShowS
    $cshow :: forall a. Show a => PGArray a -> String
    show :: PGArray a -> String
    $cshowList :: forall a. Show a => [PGArray a] -> ShowS
    showList :: [PGArray a] -> ShowS
    Show, Typeable, (forall a b. (a -> b) -> PGArray a -> PGArray b)
    -> (forall a b. a -> PGArray b -> PGArray a) -> Functor PGArray
    forall a b. a -> PGArray b -> PGArray a
    forall a b. (a -> b) -> PGArray a -> PGArray b
    forall (f :: * -> *).
    (forall a b. (a -> b) -> f a -> f b)
    -> (forall a b. a -> f b -> f a) -> Functor f
    $cfmap :: forall a b. (a -> b) -> PGArray a -> PGArray b
    fmap :: forall a b. (a -> b) -> PGArray a -> PGArray b
    $c<$ :: forall a b. a -> PGArray b -> PGArray a
    <$ :: forall a b. a -> PGArray b -> PGArray a
    Functor)

    -- | A composite type to parse your custom data structures without
    -- having to define dummy newtype wrappers every time.
    --
    --
    -- > instance FromRow MyData where ...
    --
    -- > instance FromRow MyData2 where ...
    --
    --
    -- then I can do the following for free:
    --
    -- @
    -- res <- query' c "..."
    -- forM res $ \\(MyData{..} :. MyData2{..}) -> do
    --   ....
    -- @
    data h :. t = h :. t deriving ((h :. t) -> (h :. t) -> Bool
    ((h :. t) -> (h :. t) -> Bool)
    -> ((h :. t) -> (h :. t) -> Bool) -> Eq (h :. t)
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    forall h t. (Eq h, Eq t) => (h :. t) -> (h :. t) -> Bool
    $c== :: forall h t. (Eq h, Eq t) => (h :. t) -> (h :. t) -> Bool
    == :: (h :. t) -> (h :. t) -> Bool
    $c/= :: forall h t. (Eq h, Eq t) => (h :. t) -> (h :. t) -> Bool
    /= :: (h :. t) -> (h :. t) -> Bool
    Eq,Eq (h :. t)
    Eq (h :. t) =>
    ((h :. t) -> (h :. t) -> Ordering)
    -> ((h :. t) -> (h :. t) -> Bool)
    -> ((h :. t) -> (h :. t) -> Bool)
    -> ((h :. t) -> (h :. t) -> Bool)
    -> ((h :. t) -> (h :. t) -> Bool)
    -> ((h :. t) -> (h :. t) -> h :. t)
    -> ((h :. t) -> (h :. t) -> h :. t)
    -> Ord (h :. t)
    (h :. t) -> (h :. t) -> Bool
    (h :. t) -> (h :. t) -> Ordering
    (h :. t) -> (h :. t) -> h :. t
    forall a.
    Eq a =>
    (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    forall h t. (Ord h, Ord t) => Eq (h :. t)
    forall h t. (Ord h, Ord t) => (h :. t) -> (h :. t) -> Bool
    forall h t. (Ord h, Ord t) => (h :. t) -> (h :. t) -> Ordering
    forall h t. (Ord h, Ord t) => (h :. t) -> (h :. t) -> h :. t
    $ccompare :: forall h t. (Ord h, Ord t) => (h :. t) -> (h :. t) -> Ordering
    compare :: (h :. t) -> (h :. t) -> Ordering
    $c< :: forall h t. (Ord h, Ord t) => (h :. t) -> (h :. t) -> Bool
    < :: (h :. t) -> (h :. t) -> Bool
    $c<= :: forall h t. (Ord h, Ord t) => (h :. t) -> (h :. t) -> Bool
    <= :: (h :. t) -> (h :. t) -> Bool
    $c> :: forall h t. (Ord h, Ord t) => (h :. t) -> (h :. t) -> Bool
    > :: (h :. t) -> (h :. t) -> Bool
    $c>= :: forall h t. (Ord h, Ord t) => (h :. t) -> (h :. t) -> Bool
    >= :: (h :. t) -> (h :. t) -> Bool
    $cmax :: forall h t. (Ord h, Ord t) => (h :. t) -> (h :. t) -> h :. t
    max :: (h :. t) -> (h :. t) -> h :. t
    $cmin :: forall h t. (Ord h, Ord t) => (h :. t) -> (h :. t) -> h :. t
    min :: (h :. t) -> (h :. t) -> h :. t
    Ord,Int -> (h :. t) -> ShowS
    [h :. t] -> ShowS
    (h :. t) -> String
    (Int -> (h :. t) -> ShowS)
    -> ((h :. t) -> String) -> ([h :. t] -> ShowS) -> Show (h :. t)
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    forall h t. (Show h, Show t) => Int -> (h :. t) -> ShowS
    forall h t. (Show h, Show t) => [h :. t] -> ShowS
    forall h t. (Show h, Show t) => (h :. t) -> String
    $cshowsPrec :: forall h t. (Show h, Show t) => Int -> (h :. t) -> ShowS
    showsPrec :: Int -> (h :. t) -> ShowS
    $cshow :: forall h t. (Show h, Show t) => (h :. t) -> String
    show :: (h :. t) -> String
    $cshowList :: forall h t. (Show h, Show t) => [h :. t] -> ShowS
    showList :: [h :. t] -> ShowS
    Show,ReadPrec [h :. t]
    ReadPrec (h :. t)
    Int -> ReadS (h :. t)
    ReadS [h :. t]
    (Int -> ReadS (h :. t))
    -> ReadS [h :. t]
    -> ReadPrec (h :. t)
    -> ReadPrec [h :. t]
    -> Read (h :. t)
    forall a.
    (Int -> ReadS a)
    -> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
    forall h t. (Read h, Read t) => ReadPrec [h :. t]
    forall h t. (Read h, Read t) => ReadPrec (h :. t)
    forall h t. (Read h, Read t) => Int -> ReadS (h :. t)
    forall h t. (Read h, Read t) => ReadS [h :. t]
    $creadsPrec :: forall h t. (Read h, Read t) => Int -> ReadS (h :. t)
    readsPrec :: Int -> ReadS (h :. t)
    $creadList :: forall h t. (Read h, Read t) => ReadS [h :. t]
    readList :: ReadS [h :. t]
    $creadPrec :: forall h t. (Read h, Read t) => ReadPrec (h :. t)
    readPrec :: ReadPrec (h :. t)
    $creadListPrec :: forall h t. (Read h, Read t) => ReadPrec [h :. t]
    readListPrec :: ReadPrec [h :. t]
    Read,Typeable)

    infixr 3 :.

    newtype Savepoint = Savepoint Query
        deriving (Savepoint -> Savepoint -> Bool
    (Savepoint -> Savepoint -> Bool)
    -> (Savepoint -> Savepoint -> Bool) -> Eq Savepoint
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: Savepoint -> Savepoint -> Bool
    == :: Savepoint -> Savepoint -> Bool
    $c/= :: Savepoint -> Savepoint -> Bool
    /= :: Savepoint -> Savepoint -> Bool
    Eq, Eq Savepoint
    Eq Savepoint =>
    (Savepoint -> Savepoint -> Ordering)
    -> (Savepoint -> Savepoint -> Bool)
    -> (Savepoint -> Savepoint -> Bool)
    -> (Savepoint -> Savepoint -> Bool)
    -> (Savepoint -> Savepoint -> Bool)
    -> (Savepoint -> Savepoint -> Savepoint)
    -> (Savepoint -> Savepoint -> Savepoint)
    -> Ord Savepoint
    Savepoint -> Savepoint -> Bool
    Savepoint -> Savepoint -> Ordering
    Savepoint -> Savepoint -> Savepoint
    forall a.
    Eq a =>
    (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    $ccompare :: Savepoint -> Savepoint -> Ordering
    compare :: Savepoint -> Savepoint -> Ordering
    $c< :: Savepoint -> Savepoint -> Bool
    < :: Savepoint -> Savepoint -> Bool
    $c<= :: Savepoint -> Savepoint -> Bool
    <= :: Savepoint -> Savepoint -> Bool
    $c> :: Savepoint -> Savepoint -> Bool
    > :: Savepoint -> Savepoint -> Bool
    $c>= :: Savepoint -> Savepoint -> Bool
    >= :: Savepoint -> Savepoint -> Bool
    $cmax :: Savepoint -> Savepoint -> Savepoint
    max :: Savepoint -> Savepoint -> Savepoint
    $cmin :: Savepoint -> Savepoint -> Savepoint
    min :: Savepoint -> Savepoint -> Savepoint
    Ord, Int -> Savepoint -> ShowS
    [Savepoint] -> ShowS
    Savepoint -> String
    (Int -> Savepoint -> ShowS)
    -> (Savepoint -> String)
    -> ([Savepoint] -> ShowS)
    -> Show Savepoint
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> Savepoint -> ShowS
    showsPrec :: Int -> Savepoint -> ShowS
    $cshow :: Savepoint -> String
    show :: Savepoint -> String
    $cshowList :: [Savepoint] -> ShowS
    showList :: [Savepoint] -> ShowS
    Show, ReadPrec [Savepoint]
    ReadPrec Savepoint
    Int -> ReadS Savepoint
    ReadS [Savepoint]
    (Int -> ReadS Savepoint)
    -> ReadS [Savepoint]
    -> ReadPrec Savepoint
    -> ReadPrec [Savepoint]
    -> Read Savepoint
    forall a.
    (Int -> ReadS a)
    -> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
    $creadsPrec :: Int -> ReadS Savepoint
    readsPrec :: Int -> ReadS Savepoint
    $creadList :: ReadS [Savepoint]
    readList :: ReadS [Savepoint]
    $creadPrec :: ReadPrec Savepoint
    readPrec :: ReadPrec Savepoint
    $creadListPrec :: ReadPrec [Savepoint]
    readListPrec :: ReadPrec [Savepoint]
    Read, Typeable)

    -- | Represents a @VALUES@ table literal,  usable as an alternative to
    --   'Database.PostgreSQL.Simple.executeMany' and
    --   'Database.PostgreSQL.Simple.returning'.  The main advantage is that
    --   you can parametrize more than just a single @VALUES@ expression.
    --   For example,  here's a query to insert a thing into one table
    --   and some attributes of that thing into another,   returning the
    --   new id generated by the database:
    --
    --
    -- > query c [sql|
    -- >     WITH new_thing AS (
    -- >       INSERT INTO thing (name) VALUES (?) RETURNING id
    -- >     ), new_attributes AS (
    -- >       INSERT INTO thing_attributes
    -- >          SELECT new_thing.id, attrs.*
    -- >            FROM new_thing JOIN ? attrs ON TRUE
    -- >     ) SELECT * FROM new_thing
    -- >  |] ("foo", Values [  "int4", "text"    ]
    -- >                    [ ( 1    , "hello" )
    -- >                    , ( 2    , "world" ) ])
    --
    --   (Note this example uses writable common table expressions,
    --    which were added in PostgreSQL 9.1)
    --
    --   The second parameter gets expanded into the following SQL syntax:
    --
    -- > (VALUES (1::"int4",'hello'::"text"),(2,'world'))
    --
    --   When the list of attributes is empty,  the second parameter expands to:
    --
    -- > (VALUES (null::"int4",null::"text") LIMIT 0)
    --
    --   By contrast, @executeMany@ and @returning@ don't issue the query
    --   in the empty case, and simply return @0@ and @[]@ respectively.
    --   This behavior is usually correct given their intended use cases,
    --   but would certainly be wrong in the example above.
    --
    --   The first argument is a list of postgresql type names.  Because this
    --   is turned into a properly quoted identifier,  the type name is case
    --   sensitive and must be as it appears in the @pg_type@ table.   Thus,
    --   you must write @timestamptz@ instead of @timestamp with time zone@,
    --   @int4@ instead of @integer@ or @serial@, @_int8@ instead of @bigint[]@,
    --   etcetera.
    --
    --   You may omit the type names,  however,  if you do so the list
    --   of values must be non-empty,  and postgresql must be able to infer
    --   the types of the columns from the surrounding context.   If the first
    --   condition is not met,  postgresql-simple will throw an exception
    --   without issuing the query.   In the second case,  the postgres server
    --   will return an error which will be turned into a @SqlError@ exception.
    --
    --   See <https://www.postgresql.org/docs/9.5/static/sql-values.html> for
    --   more information.
    data Values a = Values [QualifiedIdentifier] [a]
        deriving (Values a -> Values a -> Bool
    (Values a -> Values a -> Bool)
    -> (Values a -> Values a -> Bool) -> Eq (Values a)
    forall a. Eq a => Values a -> Values a -> Bool
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: forall a. Eq a => Values a -> Values a -> Bool
    == :: Values a -> Values a -> Bool
    $c/= :: forall a. Eq a => Values a -> Values a -> Bool
    /= :: Values a -> Values a -> Bool
    Eq, Eq (Values a)
    Eq (Values a) =>
    (Values a -> Values a -> Ordering)
    -> (Values a -> Values a -> Bool)
    -> (Values a -> Values a -> Bool)
    -> (Values a -> Values a -> Bool)
    -> (Values a -> Values a -> Bool)
    -> (Values a -> Values a -> Values a)
    -> (Values a -> Values a -> Values a)
    -> Ord (Values a)
    Values a -> Values a -> Bool
    Values a -> Values a -> Ordering
    Values a -> Values a -> Values a
    forall a.
    Eq a =>
    (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    forall a. Ord a => Eq (Values a)
    forall a. Ord a => Values a -> Values a -> Bool
    forall a. Ord a => Values a -> Values a -> Ordering
    forall a. Ord a => Values a -> Values a -> Values a
    $ccompare :: forall a. Ord a => Values a -> Values a -> Ordering
    compare :: Values a -> Values a -> Ordering
    $c< :: forall a. Ord a => Values a -> Values a -> Bool
    < :: Values a -> Values a -> Bool
    $c<= :: forall a. Ord a => Values a -> Values a -> Bool
    <= :: Values a -> Values a -> Bool
    $c> :: forall a. Ord a => Values a -> Values a -> Bool
    > :: Values a -> Values a -> Bool
    $c>= :: forall a. Ord a => Values a -> Values a -> Bool
    >= :: Values a -> Values a -> Bool
    $cmax :: forall a. Ord a => Values a -> Values a -> Values a
    max :: Values a -> Values a -> Values a
    $cmin :: forall a. Ord a => Values a -> Values a -> Values a
    min :: Values a -> Values a -> Values a
    Ord, Int -> Values a -> ShowS
    [Values a] -> ShowS
    Values a -> String
    (Int -> Values a -> ShowS)
    -> (Values a -> String) -> ([Values a] -> ShowS) -> Show (Values a)
    forall a. Show a => Int -> Values a -> ShowS
    forall a. Show a => [Values a] -> ShowS
    forall a. Show a => Values a -> String
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: forall a. Show a => Int -> Values a -> ShowS
    showsPrec :: Int -> Values a -> ShowS
    $cshow :: forall a. Show a => Values a -> String
    show :: Values a -> String
    $cshowList :: forall a. Show a => [Values a] -> ShowS
    showList :: [Values a] -> ShowS
    Show, ReadPrec [Values a]
    ReadPrec (Values a)
    Int -> ReadS (Values a)
    ReadS [Values a]
    (Int -> ReadS (Values a))
    -> ReadS [Values a]
    -> ReadPrec (Values a)
    -> ReadPrec [Values a]
    -> Read (Values a)
    forall a. Read a => ReadPrec [Values a]
    forall a. Read a => ReadPrec (Values a)
    forall a. Read a => Int -> ReadS (Values a)
    forall a. Read a => ReadS [Values a]
    forall a.
    (Int -> ReadS a)
    -> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
    $creadsPrec :: forall a. Read a => Int -> ReadS (Values a)
    readsPrec :: Int -> ReadS (Values a)
    $creadList :: forall a. Read a => ReadS [Values a]
    readList :: ReadS [Values a]
    $creadPrec :: forall a. Read a => ReadPrec (Values a)
    readPrec :: ReadPrec (Values a)
    $creadListPrec :: forall a. Read a => ReadPrec [Values a]
    readListPrec :: ReadPrec [Values a]
    Read, Typeable)