Skip to content

Added COPY TO STDOUT support#720

Open
jroper wants to merge 1 commit into
pgjdbc:mainfrom
jroper:copy-out
Open

Added COPY TO STDOUT support#720
jroper wants to merge 1 commit into
pgjdbc:mainfrom
jroper:copy-out

Conversation

@jroper

@jroper jroper commented Jul 1, 2026

Copy link
Copy Markdown

Provides #332

This adds a new PostgresqlConnection.copyOut(String sql) method to support COPY ... TO STDOUT statements.

In addition, PostgresqlResult now fails when executing these statements, rather than silently dropping all the data.

[resolves pgjdbc#332]

This adds a new PostgresqlConnection.copyOut method to support
COPY ... TO STDOUT statements.

In addition, PostgresqlResult now fails when executing these statements, rather
than silently dropping all the data.
@mp911de mp911de added the type: enhancement A general enhancement label Jul 1, 2026
@mp911de mp911de self-assigned this Jul 1, 2026
@mp911de

mp911de commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

Thanks a lot, like how this change is shaped. I am not sure when I will be able to have a look, will be on vacation starting next week (just fyi).

@mp911de mp911de added this to the 1.2.0.RELEASE milestone Jul 1, 2026
@jroper

jroper commented Jul 2, 2026

Copy link
Copy Markdown
Author

One thing to note, I did consider originally adding this under PostgresqlStatement.executeCopyOut, because that would allow reusing the query parameter support from PostgresqlStatement, except then I learned that query parameters aren't supported in COPY statements by Postgres, the statement must be just plain SQL without parameters, so it made more sense to put it on PostgresqlConnection, especially given that that means it can mirror copyIn.

There's a few things that I'm not sure about - I explicitly complete the downstream sink when receiving a CopyDone. This is technically not needed since CopyDone is always followed by a CommandComplete which will always be followed by a stream complete by the upstream mechanics. I'm not sure what the consequences of one approach or the other are.

Something to be aware of, the Postgres protocol has no difficulties combining COPY TO STDOUT commands and other commands in a single query text. If we wanted to support this, we would need to add this support onto PostgresResult, eg, by adding a mapCopyOut method, so that a given result can be used as either. That's another way to implement this, one that allows more flexibility. It however doesn't mirror the copy in support, and I don't think there are any real use cases for mixing COPY TO STDOUT with any other commands, these are not transactional, it just doesn't make sense to me to do it.

I marked it as @since 1.2, under the assumption that this is a new API and therefore will warrant a minor version bump.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: enhancement A general enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants