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

Stabilityexperimental
MaintainerLeon P Smith <leon@melding-monads.com>
Safe HaskellNone

Database.PostgreSQL.Simple.Copy

Description

mid-level support for COPY IN and COPY OUT. See http://www.postgresql.org/docs/9.2/static/sql-copy.html for more information.

To use this binding, first call copy with a COPY FROM STDIN or COPY TO STDOUT query as documented in the link above. Then call getCopyData repeatedly until it returns CopyOutDone in the former case, or in the latter, call putCopyData repeatedly and then finish by calling either putCopyEnd to proceed or putCopyError to abort.

You cannot issue another query on the same connection while a copy is ongoing; this will result in an exception. It is harmless to concurrently call getNotification on a connection while it is in a copy in or copy out state, however be aware that current versions of the PostgreSQL backend will not deliver notifications to a client while a transaction is ongoing.

Synopsis

Documentation

copy :: ToRow params => Connection -> Query -> params -> IO ()Source

Issue a query that changes a connection's state to CopyIn (via a COPY FROM STDIN query) or CopyOut (via COPY TO STDOUT) query. Performs parameter subsitution.

copy_ :: Connection -> Query -> IO ()Source

Issue a query that changes a connection's state to CopyIn (via a COPY FROM STDIN query) or CopyOut (via COPY TO STDOUT) query. Does not perform parameter subsitution.

data CopyOutResult Source

Constructors

CopyOutRow !ByteString

Data representing either exactly one row of the result, or header or footer data depending on format.

CopyOutDone !Int64

No more rows, and a count of the number of rows returned.

getCopyData :: Connection -> IO CopyOutResultSource

A connection must be in the CopyOut state in order to call this function, via a COPY TO STDOUT query. If this returns a CopyOutRow, the connection remains in the CopyOut state, if it returns CopyOutDone, then the connection has reverted to the ready state.

putCopyData :: Connection -> ByteString -> IO ()Source

A connection must be in the CopyIn state in order to call this function, via a COPY FROM STDIN query. The connection remains in a CopyIn state after this function is called. Note that the data does not need to represent a single row, or even an integral number of rows. The net result of putCopyData conn a >> putCopyData conn b is the same as putCopyData conn c whenever c == BS.append a b.

putCopyEnd :: Connection -> IO Int64Source

A connection must be in the CopyIn state in order to call this function, via a COPY FROM STDIN query. Completes the COPY IN operation, changing the connection's state back to normal. Returns the number of rows processed.

putCopyError :: Connection -> ByteString -> IO ()Source

A connection must be in the CopyIn state in order to call this function, via a COPY FROM STDIN query. Aborts the COPY IN operation, changing the connection's state back to normal.