@@ -333,6 +333,42 @@ def test_array(datatype, examples, iceberg, pandas, conn_cnx):
333333 )
334334
335335
336+ @pytest .mark .skipif (
337+ not STRUCTURED_TYPES_SUPPORTED , reason = "Testing structured type feature."
338+ )
339+ def test_structured_type_binds (conn_cnx ):
340+ original_style = snowflake .connector .paramstyle
341+ snowflake .connector .paramstyle = "qmark"
342+ data = (
343+ 1 ,
344+ [True , False , True ],
345+ {"k1" : 1 , "k2" : 2 , "k3" : 3 , "k4" : 4 , "k5" : 5 },
346+ {"city" : "san jose" , "population" : 0.05 },
347+ [1.0 , 3.1 , 4.5 ],
348+ )
349+ json_data = [json .dumps (d ) for d in data ]
350+ schema = "(num number, arr_b array(boolean), map map(varchar, int), obj object(city varchar, population float), arr_f array(float))"
351+ table_name = f"arrow_structured_type_binds_test_{ random_string (5 )} "
352+ with conn_cnx () as conn :
353+ try :
354+ conn .cursor ().execute ("alter session set enable_bind_stage_v2=Enable" )
355+ conn .cursor ().execute (f"create table if not exists { table_name } { schema } " )
356+ conn .cursor ().execute (
357+ f"insert into { table_name } select ?, ?, ?, ?, ?" , json_data
358+ )
359+ result = conn .cursor ().execute (f"select * from { table_name } " ).fetchall ()
360+ assert result [0 ] == data
361+
362+ # Binds don't work with values statement yet
363+ with pytest .raises (ProgrammingError ):
364+ conn .cursor ().execute (
365+ f"insert into { table_name } values (?, ?, ?, ?, ?)" , json_data
366+ )
367+ finally :
368+ snowflake .connector .paramstyle = original_style
369+ conn .cursor ().execute (f"drop table if exists { table_name } " )
370+
371+
336372@pytest .mark .skipif (
337373 not STRUCTURED_TYPES_SUPPORTED , reason = "map type not supported in this environment"
338374)
0 commit comments