COPY IN / COPY OUT via the simple-query protocol, including the streaming copyInStream / copyOutStream variants that move data through callbacks.
Procs
proc copyIn(conn: PgConnection; sql: string; data: openArray[byte]; timeout: Duration = ZeroDuration): Future[CommandResult] {. ...raises: [Exception, ValueError, CatchableError], tags: [RootEffect, TimeEffect], forbids: [].}
- Execute COPY ... FROM STDIN with a single contiguous buffer. Slices data into CopyData messages internally. Returns the command result (e.g. "COPY 5").
proc copyIn(conn: PgConnection; sql: string; data: seq[byte]; timeout: Duration = ZeroDuration): Future[CommandResult] {. ...stackTrace: false, raises: [Exception, ValueError, CatchableError], tags: [RootEffect, TimeEffect], forbids: [].}
- Execute COPY ... FROM STDIN with a single contiguous seq[byte]. Avoids the copy that the openArray[byte] overload performs.
proc copyIn(conn: PgConnection; sql: string; data: seq[seq[byte]]; timeout: Duration = ZeroDuration): Future[CommandResult] {. ...raises: [Exception, ValueError, CatchableError], tags: [RootEffect, TimeEffect], forbids: [].}
- Execute COPY ... FROM STDIN via simple query protocol. Concatenates chunks and delegates to the seq[byte] overload. Returns the command result (e.g. "COPY 5").
proc copyIn(conn: PgConnection; sql: string; data: string; timeout: Duration = ZeroDuration): Future[CommandResult] {. ...raises: [Exception, ValueError, CatchableError], tags: [RootEffect, TimeEffect], forbids: [].}
- Execute COPY ... FROM STDIN with text data as a string. Converts to bytes internally; avoids manual toOpenArrayByte.
proc copyInRawImpl(conn: PgConnection; sql: string; data: seq[byte]; timeout: Duration = ZeroDuration): Future[string] {. ...stackTrace: false, raises: [Exception, ValueError, PgConnectionError, SslError, ProtocolError, PgQueryError, AsyncTimeoutError, CatchableError], tags: [RootEffect, TimeEffect], forbids: [].}
proc copyInStream(conn: PgConnection; sql: string; callback: CopyInCallback; timeout: Duration = ZeroDuration): Future[CopyInInfo] {. ...stackTrace: false, raises: [Exception, ValueError, CatchableError], tags: [RootEffect, TimeEffect], forbids: [].}
- Execute COPY ... FROM STDIN via simple query protocol, streaming data from callback. The callback is called repeatedly; returning an empty seq[byte] signals EOF. If the callback raises, CopyFail is sent and the connection returns to csReady. On timeout, the connection is marked csClosed (protocol out of sync).
proc copyInStreamImpl(conn: PgConnection; sql: string; callback: CopyInCallback; timeout: Duration = ZeroDuration): Future[CopyInInfo] {. ...stackTrace: false, raises: [Exception, ValueError, PgConnectionError, SslError, ProtocolError, PgQueryError, AsyncTimeoutError, CatchableError], tags: [RootEffect, TimeEffect], forbids: [].}
proc copyOut(conn: PgConnection; sql: string; timeout: Duration = ZeroDuration): Future[ CopyResult] {....stackTrace: false, raises: [Exception, ValueError, CatchableError], tags: [RootEffect, TimeEffect], forbids: [].}
- Execute COPY ... TO STDOUT via simple query protocol. Collects all CopyData messages and returns them in a CopyResult. On timeout, the connection is marked csClosed (protocol out of sync).
proc copyOutImpl(conn: PgConnection; sql: string; timeout: Duration = ZeroDuration): Future[CopyResult] {. ...stackTrace: false, raises: [Exception, ValueError, PgConnectionError, SslError, ProtocolError, PgQueryError, AsyncTimeoutError, CatchableError], tags: [RootEffect, TimeEffect], forbids: [].}
proc copyOutStream(conn: PgConnection; sql: string; callback: CopyOutCallback; timeout: Duration = ZeroDuration): Future[CopyOutInfo] {. ...stackTrace: false, raises: [Exception, ValueError, CatchableError], tags: [RootEffect, TimeEffect], forbids: [].}
-
Execute COPY ... TO STDOUT via simple query protocol, streaming each CopyData chunk through callback. The callback is awaited, providing natural TCP backpressure.
If the callback raises, COPY OUT has no client->server abort (CopyFail is COPY IN only), so the remaining CopyData is drained up to ReadyForQuery to keep the protocol in sync; the connection returns to csReady and stays usable, and the callback's error is then re-raised. Because the server still streams the whole result before ReadyForQuery, a callback failure on an early chunk of a large COPY can mean draining a substantial amount of data before the error surfaces — cancel the query out-of-band (cancel) if you need to abort a large COPY OUT promptly. On timeout the connection is instead marked csClosed (protocol out of sync).
proc copyOutStreamImpl(conn: PgConnection; sql: string; callback: CopyOutCallback; timeout: Duration = ZeroDuration): Future[CopyOutInfo] {. ...stackTrace: false, raises: [Exception, ValueError, PgConnectionError, SslError, ProtocolError, AsyncTimeoutError, CatchableError, PgQueryError], tags: [RootEffect, TimeEffect], forbids: [].}