Skip to content

Commit fbfe133

Browse files
committed
Escape backslashes in string values
1 parent b609e27 commit fbfe133

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

target_postgres/sinks.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,12 @@ def bulk_insert_records( # type: ignore[override]
180180
]
181181

182182
# Make translation table for escaping in array values.
183+
str_translate_table = str.maketrans(
184+
{
185+
'"': '""',
186+
"\\": "\\\\",
187+
}
188+
)
183189
array_translate_table = str.maketrans(
184190
{
185191
'"': '\\""',
@@ -200,7 +206,7 @@ def process_column_value(data: Any, proc: Callable) -> str:
200206
# a quoted value.
201207
if isinstance(value, str):
202208
# escape double quotes as "".
203-
return '"' + value.replace('"', '""') + '"'
209+
return '"' + value.translate(str_translate_table) + '"'
204210

205211
# If the value is a list (for ARRAY), escape double-quotes as \" and return
206212
# a quoted value in literal array format.

0 commit comments

Comments
 (0)