Skip to content

Commit

Permalink
Keep single quotes in InsertIntoWriter (#128)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
akito19 authored Jun 3, 2024
1 parent 708e8c5 commit 203b703
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pytd/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,13 @@ def _build_query(self, database, table, list_of_tuple, column_names):
"""
rows = []
for tpl in list_of_tuple:
# InsertIntoWriter kicks Presto (Trino).
# Following the list comprehension makes a single quote duplicated because
# Presto allows users to escape a single quote with another single quote.
# e.g. 'John Doe''s name' is converted to "John Doe's name" on Presto.
list_of_value_strings = [
(
f"""'{e.replace("'", '"')}'"""
f"""'{e.replace("'", "''")}'"""
if isinstance(e, str)
else ("null" if pd.isnull(e) else str(e))
)
Expand Down

0 comments on commit 203b703

Please sign in to comment.