Skip to content

Support binary data transfer in COPY FROM #573

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

ahoppen
Copy link
Contributor

@ahoppen ahoppen commented Jul 24, 2025

Depends on #566


My benchmark of transferring the integers from 0 to 1,000,000 both as an integer and as a string was about the same speed as the old text-based transfer. I believe that the binary transfer will start to show significant benefits when transferring binary data, other fields that don't need to be represented as fields and also means that the user doesn't need to worry about escapping their data.

A call to binary transfer data looks as follows

let records: [(id: Int, name: String)] = [(1, "Alice"), (42, "Bob")]
try await conn.copyFromBinary(table: "copy_table", columns: ["id", "name"], logger: .psqlTest) { writer in
    for record in records {
        try await writer.writeRow { columnWriter in
            try columnWriter.writeColumn(Int32(record.id))
            try columnWriter.writeColumn(record.name)
        }
    }
}

My benchmark of transferring the integers from 0 to 1,000,000 both as an integer and as a string was about the same speed as the old text-based transfer. I believe that the binary transfer will start to show significant benefits when transferring binary data, other fields that don't need to be represented as fields and also means that the user doesn't need to worry about escapping their data.
@ahoppen ahoppen force-pushed the copy-from-binary branch from 8032167 to 9650d8c Compare July 24, 2025 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant