Skip to content

postgres: \COPY meta command isn't supported? #1534

Answered by abonander
akiradeveloper asked this question in Q&A
Discussion options

You must be logged in to vote

\COPY as a meta command is specifically a feature of the psql client.

Good news, though, this functionality is available. You can call the following method on PgPool: https://docs.rs/sqlx/0.5.9/sqlx/struct.Pool.html#method.copy_in_raw

By mistake, the PgCopyIn type isn't exported, but you can see the public methods on it in the source here: https://github.com/launchbadge/sqlx/blob/master/sqlx-core/src/postgres/copy.rs#L142

Usage would look something like this (with Tokio):

let file = tokio::fs::File::open("/tmp/yyyy").await?;

// pg_pool: PgPool
let mut copy_in = pg_pool.copy_in_raw("COPY xxxx FROM STDIN (FORMAT CSV)").await?;

copy_in.read_from(file).await?;

let rows_inserted = copy_in.f…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@akiradeveloper
Comment options

@CraftedQuake
Comment options

@abonander
Comment options

@CraftedQuake
Comment options

Answer selected by abonander
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #1533 on November 11, 2021 09:30.