Implement automatic E-prefix detection for escaped string literals #33
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.
Implement automatic E-prefix detection for escaped string literals in PostgreSQL
Problem
The deparser was not automatically adding the
Eprefix to string literals containing backslash escape sequences, which is required for proper PostgreSQL syntax whenstandard_conforming_strings=on(the default since PostgreSQL 9.1).Solution
Implemented automatic E-prefix detection logic that:
E'...'syntax when neededTechnical Implementation
New
needsEscapePrefix()methodEnhanced string processing
\\\\and quotes as''in E-prefixed stringsExamples
Input AST string values:
"a\bcd"→E'a\\bcd'"a\b'cd"→E'a\\b''cd'"ab\'cd"→E'ab\\''cd'"\\"→E'\\\\'Regular strings without escapes:
"hello world"→'hello world'(no E-prefix needed)Testing
PostgreSQL Compatibility
This implementation follows PostgreSQL's string literal syntax requirements:
standard_conforming_strings=on(default since PostgreSQL 9.1)Link to Devin run: https://app.devin.ai/sessions/53c6e39590e9403ab99a25afe0dd5e99
Requested by: Dan Lynch ([email protected])