#4386·sqlx

postgres: add high-level API for COPY TO/FROM

Author: yboyiCreated Aug 18, 2026Updated Sep 18, 2026
Labelsenhancement

I have found these related issues/pull requests

none

Description

While sqlx does provide some low-level, raw APIs for postgres' copy API (https://www.postgresql.org/docs/current/sql-copy.html):

but it requires also a lot of boilerplate that is not handled by the lib as of now:

  • encoding/decoding - in my project I fell back to using CSV as the easiest to replicate format. Not sure if there are available encoders/decoders for the format postgres expects out there
  • nuances with not reading the stream to completion - would be great to handle it with a drop impl or something similar, instead of manual calls to finish.
  • no type-checking with query! macro against the database schema

There's implementation by tokio_postgres https://docs.rs/tokio-postgres/latest/tokio_postgres/binary_copy/index.html, but it doesn't expose public API for the parser itself, and even if it did, we'd end up with mixing two different driver implementations

Prefered solution

A high-level API, integrated with sqlx::query! macro to type-check against the actual databse, with at least text and binary formats supported as wire formats

Is this a breaking change? Why or why not?

Not a breaking change, as it only adds new API, which shouldn't break old downstream code.