hpgsql
Safe HaskellNone
LanguageHaskell2010

Hpgsql.Copy

Synopsis

Documentation

withCopy :: HPgConnection -> Query -> IO a -> IO (Int64, a) Source #

Runs a COPY FROM STDIN statement, giving you the ability to pass a row-inserting function.

withCopy conn "COPY employee FROM STDIN WITH (FORMAT CSV)" $ do
   putCopyData conn "5,Dracula\n"
   putCopyData conn "6,The Grinch\n"

You can also use copyFromS for binary COPY.

Note on interruption safety: if this is interrupted by an asynchronous exception while running inside a transaction, hpgsql will throw an exception on the next statement. This happens because hpgsql would change semantics if it aborted the COPY statement - because it would abort the entire transaction -, and it couldn't "complete" the COPY either due to the risk of not all rows having been inserted.

withCopy_ :: HPgConnection -> Query -> IO a -> IO Int64 Source #

Runs a COPY FROM STDIN statement, giving you the ability to pass a row-inserting function.

withCopy_ conn "COPY employee FROM STDIN WITH (FORMAT CSV)" $ do
   putCopyData conn "5,Dracula\n"
   putCopyData conn "6,The Grinch\n"

You can also use copyFromS for binary COPY.

Note on interruption safety: if this is interrupted by an asynchronous exception while running inside a transaction, hpgsql will throw an exception on the next statement. This happens because hpgsql would change semantics if it aborted the COPY statement - because it would abort the entire transaction -, and it couldn't "complete" the COPY either due to the risk of not all rows having been inserted.

copyFrom :: ToPgRow r => HPgConnection -> Query -> [r] -> IO Int64 Source #

Copies rows into a table with the binary COPY protocol. This must be a "COPY table FROM STDIN WITH (FORMAT BINARY)"-like statement. Returns the Stream's result and the count of inserted rows.

let rows :: [Employee]
    rows = someListOfEmployees
copyFrom conn "COPY employee FROM STDIN WITH (FORMAT BINARY)" rows

Note on interruption safety: if this is interrupted by an asynchronous exception while running inside a transaction, hpgsql will throw an exception on the next statement. This happens because hpgsql would change semantics if it aborted the COPY statement - because it would abort the entire transaction -, and it couldn't "complete" the COPY either due to the risk of not all rows having been inserted.

copyFromS :: ToPgRow r => HPgConnection -> Query -> Stream (Of r) IO b -> IO (Int64, b) Source #

Copies rows into a table with the binary COPY protocol. This must be a "COPY table FROM STDIN WITH (FORMAT BINARY)"-like statement. Returns the Stream's result and the count of inserted rows.

let rows :: Stream (Of Employee) IO ()
    rows = someStreamOfEmployees
copyFromS conn "COPY employee FROM STDIN WITH (FORMAT BINARY)" rows

Note on interruption safety: if this is interrupted by an asynchronous exception while running inside a transaction, hpgsql will throw an exception on the next statement. This happens because hpgsql would change semantics if it aborted the COPY statement - because it would abort the entire transaction -, and it couldn't "complete" the COPY either due to the risk of not all rows having been inserted.