Repository navigation
PostgreSQL: Escape quotes in COPY option values - #2784
Open
LucaCappelletti94 wants to merge 1 commit into
Open
LucaCappelletti94 wants to merge 1 commit into
LucaCappelletti94 wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2784 +/- ##
==========================================
+ Coverage 82.83% 82.85% +0.01%
==========================================
Files 42 42
Lines 35900 35908 +8
Branches 35900 35908 +8
==========================================
+ Hits 29739 29750 +11
+ Misses 2654 2651 -3
Partials 3507 3507 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
slopgobblercobbler
left a comment
There was a problem hiding this comment.
Audited single-quote character escaping in COPY options across src/ast/value.rs and src/ast/mod.rs:
- Root cause resolution:
- In PostgreSQL and Redshift
COPYsyntax, a literal single-quote option value (e.g.QUOTE '''orESCAPE ''') must be escaped by doubling the quote inside single quotes, producing''''. - Previously, formatting
chardirectly inside single quotes (write!(f, "QUOTE '{char}'")) yielded''', creating an unclosed string literal syntax error on re-parsing.
- In PostgreSQL and Redshift
- Display implementation and escaping:
- Introducing
EscapeSingleQuoteCharinsrc/ast/value.rsprovides a lightweight, zero-allocation display adapter that writes''whenchar == '\''and writes the character unchanged otherwise. - Applying
escape_single_quote_chartoDELIMITER,QUOTE, andESCAPEinCopyOption,CopyLegacyOption, andCopyLegacyCsvOptionensures uniform serialization across modern and legacy COPY option syntaxes. - In Redshift IAM options, applying
escape_single_quote_stringtoIamRoleKind::Arn(arn)ensures ARNs containing single quotes round-trip safely.
- Introducing
- Roundtrip invariance and test coverage:
- Unit tests in
sqlparser_postgres.rsassert exact AST identity and string roundtrips across standard options, legacy options, and Redshift IAM role strings. - Verified
parse_copy_option_quoted_chars_round_trippasses with 0 errors.
- Unit tests in
Clean, minimal fix that restores roundtrip invariance for quote-delimited COPY configurations.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
COPY y TO stdout WITH CSV QUOTE '''' DELIMITER '|'renderedQUOTE ''', which does not parse. EveryCOPYoption that prints a character or string between single quotes now escapes it. That coversDELIMITER,QUOTEandESCAPEin both option syntaxes and theIAM_ROLEARN. The string options already escaped.These are all friends of #2783 and the same consideration thereof apply also here.
https://www.postgresql.org/docs/current/sql-copy.html