copyIn

fun copyIn(sql: String): CopyIn

Initiates a COPY IN operation allowing manual chunk writing.

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

Return

The handle to write chunks through.

Parameters

sql

A COPY … FROM STDIN statement.

Throws

UNEXPECTED_RESULT if sql did not start a COPY IN.


fun copyIn(sql: String, inputStream: InputStream, bufferSize: Int = DEFAULT_BUFFER_SIZE): Long

Reads all data from the provided InputStream and writes it to the COPY IN operation.

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

Return

The number of rows the server accepted.

Parameters

sql

A COPY … FROM STDIN statement.

inputStream

The source of the data, read to exhaustion.

bufferSize

Size of the chunks the input is forwarded in. Each chunk is one message and one flush, so very small values turn a bulk load back into per-chunk round trips.

Throws

INVALID_ARGUMENT if bufferSize is not positive, UNEXPECTED_RESULT if sql did not start a COPY IN.