| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Hpgsql.Copy
Synopsis
- copyStart :: HPgConnection -> Query -> IO ()
- copyEnd :: HPgConnection -> IO Int64
- putCopyData :: HPgConnection -> ByteString -> IO ()
- putCopyError :: HPgConnection -> String -> IO ()
- withCopy :: HPgConnection -> Query -> IO a -> IO (Int64, a)
- withCopy_ :: HPgConnection -> Query -> IO a -> IO Int64
- copyFrom :: ToPgRow r => HPgConnection -> Query -> [r] -> IO Int64
- copyFromS :: ToPgRow r => HPgConnection -> Query -> Stream (Of r) IO b -> IO (Int64, b)
Documentation
putCopyData :: HPgConnection -> ByteString -> IO () Source #
putCopyError :: HPgConnection -> String -> IO () Source #
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)" rowsNote 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)" rowsNote 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.