File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -179,6 +179,14 @@ def bulk_insert_records( # type: ignore[override]
179
179
column .type .bind_processor (connection .dialect ) or str for column in columns
180
180
]
181
181
182
+ # Make translation table for escaping in array values.
183
+ array_translate_table = str .maketrans (
184
+ {
185
+ '"' : '\\ ""' ,
186
+ "\\ " : "\\ \\ " ,
187
+ }
188
+ )
189
+
182
190
def process_column_value (data : Any , proc : Callable ) -> str :
183
191
# If the data is null, return an unquoted, empty value.
184
192
# Unquoted is important here, for PostgreSQL to interpret as null.
@@ -200,7 +208,9 @@ def process_column_value(data: Any, proc: Callable) -> str:
200
208
# for each member of value, escape double quotes as \".
201
209
return (
202
210
'"{'
203
- + "," .join ('""' + v .replace ('"' , r'\""' ) + '""' for v in value )
211
+ + "," .join (
212
+ '""' + v .translate (array_translate_table ) + '""' for v in value
213
+ )
204
214
+ '}"'
205
215
)
206
216
You can’t perform that action at this time.
0 commit comments