Skip to content

Instance Method

copyFromBinary(table:columns:options:bufferSize:logger:file:line:writeData:)

Copy data into a table using a COPY <table name> FROM STDIN query, transferring data in a binary format.
func copyFromBinary(table: String, columns: [String] = [], options: PostgresCopyFromFormat.BinaryOptions = .init(), bufferSize: Int = 100_000, logger: Logger, file: String = #fileID, line: Int = #line, writeData: nonisolated(nonsending) (inout PostgresBinaryCopyFromWriter) async throws -> Void) async throws

Parameters

table

The name of the table into which to copy the data.

columns

The name of the columns to copy. If an empty array is passed, all columns are assumed to be copied.

bufferSize

How many bytes to accumulate a local buffer before flushing it to the database. Can affect performance characteristics of the copy operation.

writeData

Closure that produces the data for the table, to be streamed to the backend. Call writeRow(_:) on the writer provided by the closure to send data to the backend and return from the closure once all data is sent. Throw an error from the closure to fail the data transfer. The error thrown by the closure will be rethrown by the copyFromBinary function.

Discussion

Important

The table and column names are inserted into the COPY FROM query as passed and might thus be susceptible to SQL injection. Ensure no untrusted data is contained in these strings.