sfackler / rust-postgres

Native PostgreSQL driver for the Rust programming language
Apache License 2.0
3.52k stars 446 forks source link

Is there a way to stream a large-ish `bytea` to the database? #1179

Closed lvella closed 2 months ago

lvella commented 2 months ago

It seems that BinaryCopyInWriter only works for full rows, but I would like to a single bytea field into the database as it is received from the network. Is this possible?

sfackler commented 2 months ago

There's no way to do that with the built-in BinaryCopyInWriter. You could make a custom writer that would be able to do that (you do need to know the size of the buffer and the overall row up-front). IIRC Postgres will buffer the entire row in memory though regardless.

Depending how big these values are, you may want to consider using the large value API, which allows "real" streaming to and from the backend.

lvella commented 2 months ago

Thanks. I found your crate postgres_large_object.