@@ -3708,31 +3708,41 @@ impl<'a> Parser<'a> {
3708
3708
Keyword :: BLOB => Ok ( DataType :: Blob ( self . parse_optional_precision ( ) ?) ) ,
3709
3709
Keyword :: UUID => Ok ( DataType :: Uuid ) ,
3710
3710
Keyword :: DATE => Ok ( DataType :: Date ) ,
3711
- Keyword :: DATETIME => Ok ( DataType :: Datetime ) ,
3711
+ Keyword :: DATETIME => Ok ( DataType :: Datetime ( self . parse_optional_precision ( ) ? ) ) ,
3712
3712
Keyword :: TIMESTAMP => {
3713
- if self . parse_keyword ( Keyword :: WITH ) {
3713
+ let precision = self . parse_optional_precision ( ) ?;
3714
+ let tz = if self . parse_keyword ( Keyword :: WITH ) {
3714
3715
self . expect_keywords ( & [ Keyword :: TIME , Keyword :: ZONE ] ) ?;
3715
- Ok ( DataType :: Timestamp ( TimezoneInfo :: WithTimeZone ) )
3716
+ TimezoneInfo :: WithTimeZone
3716
3717
} else if self . parse_keyword ( Keyword :: WITHOUT ) {
3717
3718
self . expect_keywords ( & [ Keyword :: TIME , Keyword :: ZONE ] ) ?;
3718
- Ok ( DataType :: Timestamp ( TimezoneInfo :: WithoutTimeZone ) )
3719
+ TimezoneInfo :: WithoutTimeZone
3719
3720
} else {
3720
- Ok ( DataType :: Timestamp ( TimezoneInfo :: None ) )
3721
- }
3721
+ TimezoneInfo :: None
3722
+ } ;
3723
+ Ok ( DataType :: Timestamp ( precision, tz) )
3722
3724
}
3723
- Keyword :: TIMESTAMPTZ => Ok ( DataType :: Timestamp ( TimezoneInfo :: Tz ) ) ,
3725
+ Keyword :: TIMESTAMPTZ => Ok ( DataType :: Timestamp (
3726
+ self . parse_optional_precision ( ) ?,
3727
+ TimezoneInfo :: Tz ,
3728
+ ) ) ,
3724
3729
Keyword :: TIME => {
3725
- if self . parse_keyword ( Keyword :: WITH ) {
3730
+ let precision = self . parse_optional_precision ( ) ?;
3731
+ let tz = if self . parse_keyword ( Keyword :: WITH ) {
3726
3732
self . expect_keywords ( & [ Keyword :: TIME , Keyword :: ZONE ] ) ?;
3727
- Ok ( DataType :: Time ( TimezoneInfo :: WithTimeZone ) )
3733
+ TimezoneInfo :: WithTimeZone
3728
3734
} else if self . parse_keyword ( Keyword :: WITHOUT ) {
3729
3735
self . expect_keywords ( & [ Keyword :: TIME , Keyword :: ZONE ] ) ?;
3730
- Ok ( DataType :: Time ( TimezoneInfo :: WithoutTimeZone ) )
3736
+ TimezoneInfo :: WithoutTimeZone
3731
3737
} else {
3732
- Ok ( DataType :: Time ( TimezoneInfo :: None ) )
3733
- }
3738
+ TimezoneInfo :: None
3739
+ } ;
3740
+ Ok ( DataType :: Time ( precision, tz) )
3734
3741
}
3735
- Keyword :: TIMETZ => Ok ( DataType :: Time ( TimezoneInfo :: Tz ) ) ,
3742
+ Keyword :: TIMETZ => Ok ( DataType :: Time (
3743
+ self . parse_optional_precision ( ) ?,
3744
+ TimezoneInfo :: Tz ,
3745
+ ) ) ,
3736
3746
// Interval types can be followed by a complicated interval
3737
3747
// qualifier that we don't currently support. See
3738
3748
// parse_interval for a taste.
@@ -5789,6 +5799,7 @@ mod tests {
5789
5799
5790
5800
#[ cfg( test) ]
5791
5801
mod test_parse_data_type {
5802
+
5792
5803
use crate :: ast:: {
5793
5804
CharLengthUnits , CharacterLength , DataType , ExactNumberInfo , ObjectName , TimezoneInfo ,
5794
5805
} ;
@@ -5799,8 +5810,8 @@ mod tests {
5799
5810
( $dialect: expr, $input: expr, $expected_type: expr $( , ) ?) => { {
5800
5811
$dialect. run_parser_method( & * $input, |parser| {
5801
5812
let data_type = parser. parse_data_type( ) . unwrap( ) ;
5802
- assert_eq!( data_type , $expected_type) ;
5803
- assert_eq!( data_type . to_string( ) , $input . to_string( ) ) ;
5813
+ assert_eq!( $expected_type, data_type ) ;
5814
+ assert_eq!( $input . to_string( ) , data_type . to_string( ) ) ;
5804
5815
} ) ;
5805
5816
} } ;
5806
5817
}
@@ -6048,44 +6059,68 @@ mod tests {
6048
6059
}
6049
6060
6050
6061
#[ test]
6051
- fn test_ansii_datetime_types ( ) {
6062
+ fn test_ansii_date_type ( ) {
6052
6063
// Datetime types: <https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#datetime-type>
6053
6064
let dialect = TestedDialects {
6054
6065
dialects : vec ! [ Box :: new( GenericDialect { } ) , Box :: new( AnsiDialect { } ) ] ,
6055
6066
} ;
6056
6067
6057
6068
test_parse_data_type ! ( dialect, "DATE" , DataType :: Date ) ;
6058
6069
6059
- test_parse_data_type ! ( dialect, "TIME" , DataType :: Time ( TimezoneInfo :: None ) ) ;
6070
+ test_parse_data_type ! ( dialect, "TIME" , DataType :: Time ( None , TimezoneInfo :: None ) ) ;
6071
+
6072
+ test_parse_data_type ! (
6073
+ dialect,
6074
+ "TIME(6)" ,
6075
+ DataType :: Time ( Some ( 6 ) , TimezoneInfo :: None )
6076
+ ) ;
6060
6077
6061
6078
test_parse_data_type ! (
6062
6079
dialect,
6063
6080
"TIME WITH TIME ZONE" ,
6064
- DataType :: Time ( TimezoneInfo :: WithTimeZone )
6081
+ DataType :: Time ( None , TimezoneInfo :: WithTimeZone )
6082
+ ) ;
6083
+
6084
+ test_parse_data_type ! (
6085
+ dialect,
6086
+ "TIME(6) WITH TIME ZONE" ,
6087
+ DataType :: Time ( Some ( 6 ) , TimezoneInfo :: WithTimeZone )
6065
6088
) ;
6066
6089
6067
6090
test_parse_data_type ! (
6068
6091
dialect,
6069
6092
"TIME WITHOUT TIME ZONE" ,
6070
- DataType :: Time ( TimezoneInfo :: WithoutTimeZone )
6093
+ DataType :: Time ( None , TimezoneInfo :: WithoutTimeZone )
6094
+ ) ;
6095
+
6096
+ test_parse_data_type ! (
6097
+ dialect,
6098
+ "TIME(6) WITHOUT TIME ZONE" ,
6099
+ DataType :: Time ( Some ( 6 ) , TimezoneInfo :: WithoutTimeZone )
6071
6100
) ;
6072
6101
6073
6102
test_parse_data_type ! (
6074
6103
dialect,
6075
6104
"TIMESTAMP" ,
6076
- DataType :: Timestamp ( TimezoneInfo :: None )
6105
+ DataType :: Timestamp ( None , TimezoneInfo :: None )
6106
+ ) ;
6107
+
6108
+ test_parse_data_type ! (
6109
+ dialect,
6110
+ "TIMESTAMP(22)" ,
6111
+ DataType :: Timestamp ( Some ( 22 ) , TimezoneInfo :: None )
6077
6112
) ;
6078
6113
6079
6114
test_parse_data_type ! (
6080
6115
dialect,
6081
- "TIMESTAMP WITH TIME ZONE" ,
6082
- DataType :: Timestamp ( TimezoneInfo :: WithTimeZone )
6116
+ "TIMESTAMP(22) WITH TIME ZONE" ,
6117
+ DataType :: Timestamp ( Some ( 22 ) , TimezoneInfo :: WithTimeZone )
6083
6118
) ;
6084
6119
6085
6120
test_parse_data_type ! (
6086
6121
dialect,
6087
- "TIMESTAMP WITHOUT TIME ZONE" ,
6088
- DataType :: Timestamp ( TimezoneInfo :: WithoutTimeZone )
6122
+ "TIMESTAMP(33) WITHOUT TIME ZONE" ,
6123
+ DataType :: Timestamp ( Some ( 33 ) , TimezoneInfo :: WithoutTimeZone )
6089
6124
) ;
6090
6125
}
6091
6126
}
0 commit comments