@@ -74,10 +74,7 @@ def init_conns():
7474 "boolean" : [
7575 "boolean" ,
7676 ],
77- "json" : [
78- "json" ,
79- "jsonb"
80- ]
77+ "json" : ["json" , "jsonb" ],
8178 },
8279 db .MySQL : {
8380 # https://dev.mysql.com/doc/refman/8.0/en/integer-types.html
@@ -205,7 +202,7 @@ def init_conns():
205202 ],
206203 "json" : [
207204 "super" ,
208- ]
205+ ],
209206 },
210207 db .Oracle : {
211208 "int" : [
@@ -497,7 +494,7 @@ def __len__(self):
497494 "float" : FloatFaker (N_SAMPLES ),
498495 "uuid" : UUID_Faker (N_SAMPLES ),
499496 "boolean" : BooleanFaker (N_SAMPLES ),
500- "json" : JsonFaker (N_SAMPLES )
497+ "json" : JsonFaker (N_SAMPLES ),
501498}
502499
503500
@@ -607,12 +604,17 @@ def _insert_to_table(conn, table_path, values, coltype):
607604 elif isinstance (conn , db .Redshift ) and coltype in ("json" , "jsonb" ):
608605 values = [(i , Code (f"JSON_PARSE({ sample } )" )) for i , sample in values ]
609606 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+ ),
614615 )
615- )) for i , sample in values ]
616+ for i , sample in values
617+ ]
616618
617619 insert_rows_in_batches (conn , tbl , values , columns = ["id" , "col" ])
618620 conn .query (commit )
@@ -636,7 +638,7 @@ def _create_table_with_indexes(conn, table_path, type_):
636638 conn .query (tbl .create ())
637639
638640 (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" ):
640642 conn .query (f"CREATE INDEX xa_{ index_id } ON { table_name } ({ quote ('id' )} , { quote ('col' )} )" )
641643 if conn .dialect .SUPPORTS_INDEXES :
642644 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
736738
737739 # For fuzzily diffed types, some rows can be downloaded for local comparison. This happens
738740 # 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" }:
740742 self .assertEqual (0 , differ .stats .get ("rows_downloaded" , 0 ))
741743
742744 # This section downloads all rows to ensure that Python agrees with the
0 commit comments