Repository navigation
Double single quotes in sql-insert and sql-update values - #1668
Open
jayhemnani9910 wants to merge 1 commit into
Open
jayhemnani9910 wants to merge 1 commit into
jayhemnani9910 wants to merge 1 commit into
Conversation
A value with an apostrophe, like O'Brien, was written as 'O'Brien', so the generated statements did not run.
This branch has not been deployed
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.
Description
\T sql-insertandsql-updatewrite text values without escaping', so the output doesn't run as soon as a value has an apostrophe:psql:
ERROR: syntax error at or near "Brien". A value likex'); drop table people; --would also turn into extra statements when the script is replayed.escape_for_sql_statementnow doubles single quotes, giving'O''Brien'.Tested: new
test_escape_for_sql_statement_str_with_quotefails without the change;pytest tests(without features and the ssh tunnel test, which needs sshtunnel) 2674 passed, 2673 on main. Against PostgreSQL 18, the\T sql-insertoutput for the table above now loads into a copy of the table with psql and gives backO'Brien.Schema-qualified queries have a separate problem (
INSERT INTO "public.people"), which I left out of this one.Checklist
CONTRIBUTING.rst).changelog.rst.AUTHORSfile (or it's already there). It's added in Show arrays in Postgres format with the default data formats #1664.pip install pre-commit && pre-commit install).