copyOut

Initiates a COPY OUT operation allowing manual chunk reading.

The connection stays in copy mode until the stream is drained or CopyOut.cancelCopy is called, and no ordinary query can run on it meanwhile. CopyOut is AutoCloseable and cancels on close, so use { } is the safe way to hold one.

Return

The handle to read chunks through.

Parameters

sql

A COPY … TO STDOUT statement.

Throws

UNEXPECTED_RESULT if sql did not start a COPY OUT.


fun copyOut(sql: String, outputStream: OutputStream): Long

Reads all data from the COPY OUT operation and writes it to the provided OutputStream.

The transfer is aborted if anything goes wrong, so the connection is never left in copy mode. outputStream is neither flushed nor closed — that stays with the caller.

Return

The number of bytes written. PostgreSQL reports no row count for COPY OUT, so this is not the counterpart of what copyIn returns.

Parameters

sql

A COPY … TO STDOUT statement.

outputStream

Where the data is written.

Throws

UNEXPECTED_RESULT if sql did not start a COPY OUT.