File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Expand file tree Collapse file tree 1 file changed +14
-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.
@@ -197,10 +205,15 @@ def process_column_value(data: Any, proc: Callable) -> str:
197
205
# If the value is a list (for ARRAY), escape double-quotes as \" and return
198
206
# a quoted value in literal array format.
199
207
if isinstance (value , list ):
208
+ self .logger .info (f"{ value .__class__ = } " )
209
+ self .logger .info (f"{ value = } " )
210
+
200
211
# for each member of value, escape double quotes as \".
201
212
return (
202
213
'"{'
203
- + "," .join ('""' + v .replace ('"' , r'\""' ) + '""' for v in value )
214
+ + "," .join (
215
+ '""' + v .translate (array_translate_table ) + '""' for v in value
216
+ )
204
217
+ '}"'
205
218
)
206
219
You can’t perform that action at this time.
0 commit comments