Skip to content

Commit 203b703

Browse files
authored
Keep single quotes in InsertIntoWriter (#128)
InsertIntoWriter converts a single quote to a double quote because single quotes are reserved for string literals and double quotes are column name. However, this conversion will break users characters when their data have a single quote. For example, current behavior changes `St. Patrick's day` to `St. Patrick"s day` implicitly. To eliminate this issue, this pull request aims to keep single quotes.
1 parent 708e8c5 commit 203b703

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Diff for: pytd/writer.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,13 @@ def _build_query(self, database, table, list_of_tuple, column_names):
286286
"""
287287
rows = []
288288
for tpl in list_of_tuple:
289+
# InsertIntoWriter kicks Presto (Trino).
290+
# Following the list comprehension makes a single quote duplicated because
291+
# Presto allows users to escape a single quote with another single quote.
292+
# e.g. 'John Doe''s name' is converted to "John Doe's name" on Presto.
289293
list_of_value_strings = [
290294
(
291-
f"""'{e.replace("'", '"')}'"""
295+
f"""'{e.replace("'", "''")}'"""
292296
if isinstance(e, str)
293297
else ("null" if pd.isnull(e) else str(e))
294298
)

0 commit comments

Comments
 (0)