Skip to content

Add COPY IN support#112

Merged
SeanTAllen merged 2 commits intomainfrom
copy-in-protocol
Feb 13, 2026
Merged

Add COPY IN support#112
SeanTAllen merged 2 commits intomainfrom
copy-in-protocol

Conversation

@SeanTAllen
Copy link
Member

Add PostgreSQL's COPY ... FROM STDIN protocol for bulk data loading with a pull-based CopyInReceiver interface that provides O(1) bounded memory flow control.

Session API: copy_in(), send_copy_data(), finish_copy(), abort_copy(). The session calls pg_copy_ready after each send_copy_data, letting the client control data flow. On completion: pg_copy_complete(count). On failure: pg_copy_failed with ErrorResponseMessage or ClientQueryError.

New _CopyInInFlight query state manages the lifecycle. Data-stream methods use direct type matching on query_state (following the cancel pattern) since they're only valid during an active COPY.

Design: #104

Implement PostgreSQL's COPY ... FROM STDIN protocol for bulk data
loading. The pull-based CopyInReceiver interface gives callers O(1)
bounded memory: the session calls pg_copy_ready after each
send_copy_data, so the client controls data flow.

Session API: copy_in(sql, receiver), send_copy_data(data),
finish_copy(), abort_copy(reason). CopyInReceiver callbacks:
pg_copy_ready, pg_copy_complete, pg_copy_failed.

The COPY query is sent via the simple query protocol. The server
responds with CopyInResponse, then the client streams CopyData
messages, finishing with CopyDone (success) or CopyFail (abort).
The server responds with CommandComplete + ReadyForQuery on success,
or ErrorResponse + ReadyForQuery on failure.

New query state _CopyInInFlight manages the lifecycle. Data-stream
methods (send_copy_data, finish_copy, abort_copy) use direct type
matching on query_state (following the cancel pattern) rather than
going through the _QueryState interface, since they are only valid
during an active COPY.

Design: #104
@SeanTAllen SeanTAllen added the changelog - added Automatically add "Added" CHANGELOG entry on merge label Feb 13, 2026
@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label Feb 13, 2026
@ponylang-main
Copy link
Contributor

Hi @SeanTAllen,

The changelog - added label was added to this pull request; all PRs with a changelog label need to have release notes included as part of the PR. If you haven't added release notes already, please do.

Release notes are added by creating a uniquely named file in the .release-notes directory. We suggest you call the file 112.md to match the number of this pull request.

The basic format of the release notes (using markdown) should be:

## Title

End user description of changes, why it's important,
problems it solves etc.

If a breaking change, make sure to include 1 or more
examples what code would look like prior to this change
and how to update it to work after this change.

Thanks.

@SeanTAllen SeanTAllen merged commit 1a44ecf into main Feb 13, 2026
8 checks passed
@SeanTAllen SeanTAllen deleted the copy-in-protocol branch February 13, 2026 01:38
@ponylang-main ponylang-main removed the discuss during sync Should be discussed during an upcoming sync label Feb 13, 2026
github-actions bot pushed a commit that referenced this pull request Feb 13, 2026
github-actions bot pushed a commit that referenced this pull request Feb 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog - added Automatically add "Added" CHANGELOG entry on merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants