@@ -610,3 +610,85 @@ async def test_binding_identifier(conn_cnx, db_parameters):
610
610
""" ,
611
611
(db_parameters ["name" ],),
612
612
)
613
+
614
+
615
+ async def create_or_replace_table (cur , table_name : str , columns ):
616
+ sql = f"CREATE OR REPLACE TEMP TABLE { table_name } ({ ',' .join (columns )} )"
617
+ await cur .execute (sql )
618
+
619
+
620
+ async def insert_multiple_records (
621
+ cur ,
622
+ table_name : str ,
623
+ ts : str ,
624
+ row_count : int ,
625
+ should_bind : bool ,
626
+ ):
627
+ sql = f"INSERT INTO { table_name } values (?)"
628
+ dates = [[ts ] for _ in range (row_count )]
629
+ await cur .executemany (sql , dates )
630
+ is_bind_sql_scoped = "SHOW stages like 'SNOWPARK_TEMP_STAGE_BIND'"
631
+ is_bind_sql_non_scoped = "SHOW stages like 'SYSTEMBIND'"
632
+ res1 = await (await cur .execute (is_bind_sql_scoped )).fetchall ()
633
+ res2 = await (await cur .execute (is_bind_sql_non_scoped )).fetchall ()
634
+ if should_bind :
635
+ assert len (res1 ) != 0 or len (res2 ) != 0
636
+ else :
637
+ assert len (res1 ) == 0 and len (res2 ) == 0
638
+
639
+
640
+ @pytest .mark .skipolddriver
641
+ @pytest .mark .parametrize (
642
+ "timestamp_type, timestamp_precision, timestamp, expected_style" ,
643
+ [
644
+ ("TIMESTAMPTZ" , 6 , "2023-03-15 13:17:29.207 +05:00" , "%Y-%m-%d %H:%M:%S.%f %z" ),
645
+ ("TIMESTAMP" , 6 , "2023-03-15 13:17:29.207" , "%Y-%m-%d %H:%M:%S.%f" ),
646
+ (
647
+ "TIMESTAMPLTZ" ,
648
+ 6 ,
649
+ "2023-03-15 13:17:29.207 +05:00" ,
650
+ "%Y-%m-%d %H:%M:%S.%f %z" ,
651
+ ),
652
+ (
653
+ "TIMESTAMPTZ" ,
654
+ None ,
655
+ "2023-03-15 13:17:29.207 +05:00" ,
656
+ "%Y-%m-%d %H:%M:%S.%f %z" ,
657
+ ),
658
+ ("TIMESTAMP" , None , "2023-03-15 13:17:29.207" , "%Y-%m-%d %H:%M:%S.%f" ),
659
+ (
660
+ "TIMESTAMPLTZ" ,
661
+ None ,
662
+ "2023-03-15 13:17:29.207 +05:00" ,
663
+ "%Y-%m-%d %H:%M:%S.%f %z" ,
664
+ ),
665
+ ("TIMESTAMPNTZ" , 6 , "2023-03-15 13:17:29.207" , "%Y-%m-%d %H:%M:%S.%f" ),
666
+ ("TIMESTAMPNTZ" , None , "2023-03-15 13:17:29.207" , "%Y-%m-%d %H:%M:%S.%f" ),
667
+ ],
668
+ )
669
+ async def test_timestamp_bindings (
670
+ conn_cnx , timestamp_type , timestamp_precision , timestamp , expected_style
671
+ ):
672
+ column_name = (
673
+ f"ts { timestamp_type } ({ timestamp_precision } )"
674
+ if timestamp_precision is not None
675
+ else f"ts { timestamp_type } "
676
+ )
677
+ table_name = f"TEST_TIMESTAMP_BINDING_{ random_string (10 )} "
678
+ binding_threshold = 65280
679
+
680
+ async with conn_cnx (paramstyle = "qmark" ) as cnx :
681
+ async with cnx .cursor () as cur :
682
+ await create_or_replace_table (cur , table_name , [column_name ])
683
+ await insert_multiple_records (cur , table_name , timestamp , 2 , False )
684
+ await insert_multiple_records (
685
+ cur , table_name , timestamp , binding_threshold + 1 , True
686
+ )
687
+ res = await (await cur .execute (f"select ts from { table_name } " )).fetchall ()
688
+ expected = datetime .strptime (timestamp , expected_style )
689
+ assert len (res ) == 65283
690
+ for r in res :
691
+ if timestamp_type == "TIMESTAMP" :
692
+ assert r [0 ].replace (tzinfo = None ) == expected .replace (tzinfo = None )
693
+ else :
694
+ assert r [0 ] == expected
0 commit comments