@@ -2474,7 +2474,7 @@ fn parse_extract() {
2474
2474
verified_stmt ( "SELECT EXTRACT(TIMEZONE_REGION FROM d)" ) ;
2475
2475
verified_stmt ( "SELECT EXTRACT(TIME FROM d)" ) ;
2476
2476
2477
- let dialects = all_dialects_except ( |d| d. is :: < SnowflakeDialect > ( ) || d . is :: < GenericDialect > ( ) ) ;
2477
+ let dialects = all_dialects_except ( |d| d. allow_extract_custom ( ) ) ;
2478
2478
let res = dialects. parse_sql_statements ( "SELECT EXTRACT(JIFFY FROM d)" ) ;
2479
2479
assert_eq ! (
2480
2480
ParserError :: ParserError ( "Expected: date/time field, found: JIFFY" . to_string( ) ) ,
@@ -2573,7 +2573,7 @@ fn parse_ceil_datetime() {
2573
2573
verified_stmt ( "SELECT CEIL(d TO SECOND) FROM df" ) ;
2574
2574
verified_stmt ( "SELECT CEIL(d TO MILLISECOND) FROM df" ) ;
2575
2575
2576
- let dialects = all_dialects_except ( |d| d. is :: < SnowflakeDialect > ( ) || d . is :: < GenericDialect > ( ) ) ;
2576
+ let dialects = all_dialects_except ( |d| d. allow_extract_custom ( ) ) ;
2577
2577
let res = dialects. parse_sql_statements ( "SELECT CEIL(d TO JIFFY) FROM df" ) ;
2578
2578
assert_eq ! (
2579
2579
ParserError :: ParserError ( "Expected: date/time field, found: JIFFY" . to_string( ) ) ,
@@ -2600,7 +2600,7 @@ fn parse_floor_datetime() {
2600
2600
verified_stmt ( "SELECT FLOOR(d TO SECOND) FROM df" ) ;
2601
2601
verified_stmt ( "SELECT FLOOR(d TO MILLISECOND) FROM df" ) ;
2602
2602
2603
- let dialects = all_dialects_except ( |d| d. is :: < SnowflakeDialect > ( ) || d . is :: < GenericDialect > ( ) ) ;
2603
+ let dialects = all_dialects_except ( |d| d. allow_extract_custom ( ) ) ;
2604
2604
let res = dialects. parse_sql_statements ( "SELECT FLOOR(d TO JIFFY) FROM df" ) ;
2605
2605
assert_eq ! (
2606
2606
ParserError :: ParserError ( "Expected: date/time field, found: JIFFY" . to_string( ) ) ,
@@ -10467,3 +10467,75 @@ fn test_group_by_nothing() {
10467
10467
) ;
10468
10468
}
10469
10469
}
10470
+
10471
+ #[ test]
10472
+ fn test_extract_seconds_ok ( ) {
10473
+ let dialects = all_dialects_where ( |d| d. allow_extract_custom ( ) ) ;
10474
+ let stmt = dialects. verified_expr ( "EXTRACT(seconds FROM '2 seconds'::INTERVAL)" ) ;
10475
+
10476
+ assert_eq ! (
10477
+ stmt,
10478
+ Expr :: Extract {
10479
+ field: DateTimeField :: Custom ( Ident {
10480
+ value: "seconds" . to_string( ) ,
10481
+ quote_style: None ,
10482
+ } ) ,
10483
+ syntax: ExtractSyntax :: From ,
10484
+ expr: Box :: new( Expr :: Cast {
10485
+ kind: CastKind :: DoubleColon ,
10486
+ expr: Box :: new( Expr :: Value ( Value :: SingleQuotedString (
10487
+ "2 seconds" . to_string( )
10488
+ ) ) ) ,
10489
+ data_type: DataType :: Interval ,
10490
+ format: None ,
10491
+ } ) ,
10492
+ }
10493
+ )
10494
+ }
10495
+
10496
+ #[ test]
10497
+ fn test_extract_seconds_single_quote_ok ( ) {
10498
+ let dialects = all_dialects_where ( |d| d. allow_extract_custom ( ) ) ;
10499
+ let stmt = dialects. verified_expr ( r#"EXTRACT('seconds' FROM '2 seconds'::INTERVAL)"# ) ;
10500
+
10501
+ assert_eq ! (
10502
+ stmt,
10503
+ Expr :: Extract {
10504
+ field: DateTimeField :: Custom ( Ident {
10505
+ value: "seconds" . to_string( ) ,
10506
+ quote_style: Some ( '\'' ) ,
10507
+ } ) ,
10508
+ syntax: ExtractSyntax :: From ,
10509
+ expr: Box :: new( Expr :: Cast {
10510
+ kind: CastKind :: DoubleColon ,
10511
+ expr: Box :: new( Expr :: Value ( Value :: SingleQuotedString (
10512
+ "2 seconds" . to_string( )
10513
+ ) ) ) ,
10514
+ data_type: DataType :: Interval ,
10515
+ format: None ,
10516
+ } ) ,
10517
+ }
10518
+ )
10519
+ }
10520
+
10521
+ #[ test]
10522
+ fn test_extract_seconds_err ( ) {
10523
+ let sql = "SELECT EXTRACT(seconds FROM '2 seconds'::INTERVAL)" ;
10524
+ let dialects = all_dialects_except ( |d| d. allow_extract_custom ( ) ) ;
10525
+ let err = dialects. parse_sql_statements ( sql) . unwrap_err ( ) ;
10526
+ assert_eq ! (
10527
+ err. to_string( ) ,
10528
+ "sql parser error: Expected: date/time field, found: seconds"
10529
+ ) ;
10530
+ }
10531
+
10532
+ #[ test]
10533
+ fn test_extract_seconds_single_quote_err ( ) {
10534
+ let sql = r#"SELECT EXTRACT('seconds' FROM '2 seconds'::INTERVAL)"# ;
10535
+ let dialects = all_dialects_except ( |d| d. allow_extract_single_quotes ( ) ) ;
10536
+ let err = dialects. parse_sql_statements ( sql) . unwrap_err ( ) ;
10537
+ assert_eq ! (
10538
+ err. to_string( ) ,
10539
+ "sql parser error: Expected: date/time field, found: 'seconds'"
10540
+ ) ;
10541
+ }
0 commit comments