Skip to content

Capture the COPY ... FROM STDIN payload verbatim - #2428

Open
LucaCappelletti94 wants to merge 2 commits into
apache:mainfrom
LucaCappelletti94:copy-stdin-verbatim-payload
Open

Capture the COPY ... FROM STDIN payload verbatim#2428
LucaCappelletti94 wants to merge 2 commits into
apache:mainfrom
LucaCappelletti94:copy-stdin-verbatim-payload

Conversation

@LucaCappelletti94

Copy link
Copy Markdown
Contributor

Parsing COPY t (a, b) FROM stdin; with two rows of two columns produced six values with nothing marking where the first row ended, so the rows could not be recovered even by counting columns. Printing the statement did not reproduce its input either, and every print and re-parse cycle inserted one more tab before each field, without bound.

The cause is that the payload was being split on tabs and newlines with \N interpreted, which is a partial implementation of the PostgreSQL text format. This removes that rather than completing it. Statement::Copy now carries payload: Option<String>, holding the text between the command and the \. terminator exactly as written, and Display writes it back unchanged. What a tab or a \N means is left to whoever consumes the statement. None means the statement carried no inline data, so a bare COPY t FROM STDIN; still prints without an invented terminator, while Some("") is an explicitly empty payload.

This breaks Statement::Copy, and Parser::parse_tsv and Parser::parse_tab_value are removed along with the format handling. Every other COPY sub-parser was already private.

My suggestion here is that either we go full csv parsing (which I agree might be a bit much), or no parsing at all (which is what I am suggesting we do in this PR), as the current impl was neither and broken.

@LucaCappelletti94
LucaCappelletti94 marked this pull request as ready for review August 4, 2026 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant