Skip to content

Translate COPY FROM STDIN into the INSERT of its rows - #156

Merged
LucaCappelletti94 merged 2 commits into
mainfrom
upstream/copy-from-stdin-inserts
Oct 24, 2026
Merged

LucaCappelletti94 merged 2 commits into
mainfrom
upstream/copy-from-stdin-inserts

Conversation

@LucaCappelletti94

Copy link
Copy Markdown
Collaborator

pg_dump writes every table's data as COPY ... FROM stdin with the rows inline, so a dump carrying data stopped at its first COPY, which pg2sqlite refused because sqlparser used to flatten the payload. sqlparser now keeps the payload verbatim, and the statement becomes one multi-row INSERT, so the load stays as atomic as the COPY was.

The payload is decoded with PostgreSQL's own rules, the text format with its backslash escapes and a null string matched before they are resolved, and CSV with quoted fields, HEADER, QUOTE, ESCAPE, FORCE_NULL and FORCE_NOT_NULL. Each field becomes a string literal, which PostgreSQL reads with the same input function COPY calls, and the INSERT then takes the ordinary translation, so every column conversion applies to it as it does to a written-out insert. Options PostgreSQL rejects, a payload without its \. line and a row with the wrong number of fields are refused, as are binary, FREEZE, ENCODING and FORCE_QUOTE. COPY TO and file or program sources stay refused.

A restore runs as the table owner, whom PostgreSQL lets past row-level security, so a COPY into a secured table writes its backing table, where the write exemption decides as for any trusted write.

This stacks on #154, which makes the boolean and numeric text pg_dump writes land as PostgreSQL stores it.

@LucaCappelletti94 LucaCappelletti94 added the enhancement New feature or request label Oct 24, 2026
@codecov

codecov Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.93617% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/impls/translator_impls/copy.rs 99.14% 3 Missing ⚠️
src/impls/translator_impls/insert.rs 92.30% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@LucaCappelletti94
LucaCappelletti94 force-pushed the upstream/copy-from-stdin-inserts branch from ac9d6b3 to 3ac419a Compare October 24, 2026 17:13
Base automatically changed from upstream/insert-string-literal-coercion to main October 24, 2026 17:13
@LucaCappelletti94
LucaCappelletti94 force-pushed the upstream/copy-from-stdin-inserts branch from 3ac419a to 9417dd6 Compare October 24, 2026 17:13
@LucaCappelletti94
LucaCappelletti94 merged commit 8b6d571 into main Oct 24, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant