@@ -74,10 +74,7 @@ def init_conns():
74
74
"boolean" : [
75
75
"boolean" ,
76
76
],
77
- "json" : [
78
- "json" ,
79
- "jsonb"
80
- ]
77
+ "json" : ["json" , "jsonb" ],
81
78
},
82
79
db .MySQL : {
83
80
# https://dev.mysql.com/doc/refman/8.0/en/integer-types.html
@@ -205,7 +202,7 @@ def init_conns():
205
202
],
206
203
"json" : [
207
204
"super" ,
208
- ]
205
+ ],
209
206
},
210
207
db .Oracle : {
211
208
"int" : [
@@ -497,7 +494,7 @@ def __len__(self):
497
494
"float" : FloatFaker (N_SAMPLES ),
498
495
"uuid" : UUID_Faker (N_SAMPLES ),
499
496
"boolean" : BooleanFaker (N_SAMPLES ),
500
- "json" : JsonFaker (N_SAMPLES )
497
+ "json" : JsonFaker (N_SAMPLES ),
501
498
}
502
499
503
500
@@ -607,12 +604,17 @@ def _insert_to_table(conn, table_path, values, coltype):
607
604
elif isinstance (conn , db .Redshift ) and coltype in ("json" , "jsonb" ):
608
605
values = [(i , Code (f"JSON_PARSE({ sample } )" )) for i , sample in values ]
609
606
elif isinstance (conn , db .PostgreSQL ) and coltype in ("json" , "jsonb" ):
610
- values = [(i , Code (
611
- "'{}'" .format (
612
- (json .dumps (sample ) if isinstance (sample , (dict , list )) else sample )
613
- .replace ('\' ' , '\' \' ' )
607
+ values = [
608
+ (
609
+ i ,
610
+ Code (
611
+ "'{}'" .format (
612
+ (json .dumps (sample ) if isinstance (sample , (dict , list )) else sample ).replace ("'" , "''" )
613
+ )
614
+ ),
614
615
)
615
- )) for i , sample in values ]
616
+ for i , sample in values
617
+ ]
616
618
617
619
insert_rows_in_batches (conn , tbl , values , columns = ["id" , "col" ])
618
620
conn .query (commit )
@@ -636,7 +638,7 @@ def _create_table_with_indexes(conn, table_path, type_):
636
638
conn .query (tbl .create ())
637
639
638
640
(index_id ,) = table_path
639
- if conn .dialect .SUPPORTS_INDEXES and type_ not in (' json' , ' jsonb' , ' array' , ' struct' ):
641
+ if conn .dialect .SUPPORTS_INDEXES and type_ not in (" json" , " jsonb" , " array" , " struct" ):
640
642
conn .query (f"CREATE INDEX xa_{ index_id } ON { table_name } ({ quote ('id' )} , { quote ('col' )} )" )
641
643
if conn .dialect .SUPPORTS_INDEXES :
642
644
conn .query (f"CREATE INDEX xb_{ index_id } ON { table_name } ({ quote ('id' )} )" )
@@ -736,7 +738,7 @@ def test_types(self, source_db, target_db, source_type, target_type, type_catego
736
738
737
739
# For fuzzily diffed types, some rows can be downloaded for local comparison. This happens
738
740
# when hashes are diferent but the essential payload is not; e.g. due to json serialization.
739
- if not {source_type , target_type } & {' json' , ' jsonb' , ' array' , ' struct' }:
741
+ if not {source_type , target_type } & {" json" , " jsonb" , " array" , " struct" }:
740
742
self .assertEqual (0 , differ .stats .get ("rows_downloaded" , 0 ))
741
743
742
744
# This section downloads all rows to ensure that Python agrees with the
0 commit comments