@@ -346,7 +346,16 @@ pub enum DataType {
346346 /// [1]: https://docs.databricks.com/aws/en/sql/language-manual/data-types/timestamp-ntz-type
347347 TimestampNtz ,
348348 /// Interval type.
349- Interval ,
349+ Interval {
350+ /// [PostgreSQL] fields specification like `INTERVAL YEAR TO MONTH`.
351+ ///
352+ /// [PostgreSQL]: https://www.postgresql.org/docs/17/datatype-datetime.html
353+ fields : Option < IntervalFields > ,
354+ /// [PostgreSQL] subsecond precision like `INTERVAL HOUR TO SECOND(3)`
355+ ///
356+ /// [PostgreSQL]: https://www.postgresql.org/docs/17/datatype-datetime.html
357+ precision : Option < u64 > ,
358+ } ,
350359 /// JSON type.
351360 JSON ,
352361 /// Binary JSON type.
@@ -635,7 +644,16 @@ impl fmt::Display for DataType {
635644 timezone,
636645 )
637646 }
638- DataType :: Interval => write ! ( f, "INTERVAL" ) ,
647+ DataType :: Interval { fields, precision } => {
648+ write ! ( f, "INTERVAL" ) ?;
649+ if let Some ( fields) = fields {
650+ write ! ( f, " {fields}" ) ?;
651+ }
652+ if let Some ( precision) = precision {
653+ write ! ( f, "({precision})" ) ?;
654+ }
655+ Ok ( ( ) )
656+ }
639657 DataType :: JSON => write ! ( f, "JSON" ) ,
640658 DataType :: JSONB => write ! ( f, "JSONB" ) ,
641659 DataType :: Regclass => write ! ( f, "REGCLASS" ) ,
@@ -889,6 +907,48 @@ impl fmt::Display for TimezoneInfo {
889907 }
890908}
891909
910+ /// Fields for [Postgres] `INTERVAL` type.
911+ ///
912+ /// [Postgres]: https://www.postgresql.org/docs/17/datatype-datetime.html
913+ #[ derive( Debug , Copy , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
914+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
915+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
916+ pub enum IntervalFields {
917+ Year ,
918+ Month ,
919+ Day ,
920+ Hour ,
921+ Minute ,
922+ Second ,
923+ YearToMonth ,
924+ DayToHour ,
925+ DayToMinute ,
926+ DayToSecond ,
927+ HourToMinute ,
928+ HourToSecond ,
929+ MinuteToSecond ,
930+ }
931+
932+ impl fmt:: Display for IntervalFields {
933+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
934+ match self {
935+ IntervalFields :: Year => write ! ( f, "YEAR" ) ,
936+ IntervalFields :: Month => write ! ( f, "MONTH" ) ,
937+ IntervalFields :: Day => write ! ( f, "DAY" ) ,
938+ IntervalFields :: Hour => write ! ( f, "HOUR" ) ,
939+ IntervalFields :: Minute => write ! ( f, "MINUTE" ) ,
940+ IntervalFields :: Second => write ! ( f, "SECOND" ) ,
941+ IntervalFields :: YearToMonth => write ! ( f, "YEAR TO MONTH" ) ,
942+ IntervalFields :: DayToHour => write ! ( f, "DAY TO HOUR" ) ,
943+ IntervalFields :: DayToMinute => write ! ( f, "DAY TO MINUTE" ) ,
944+ IntervalFields :: DayToSecond => write ! ( f, "DAY TO SECOND" ) ,
945+ IntervalFields :: HourToMinute => write ! ( f, "HOUR TO MINUTE" ) ,
946+ IntervalFields :: HourToSecond => write ! ( f, "HOUR TO SECOND" ) ,
947+ IntervalFields :: MinuteToSecond => write ! ( f, "MINUTE TO SECOND" ) ,
948+ }
949+ }
950+ }
951+
892952/// Additional information for `NUMERIC`, `DECIMAL`, and `DEC` data types
893953/// following the 2016 [SQL Standard].
894954///
@@ -902,7 +962,7 @@ pub enum ExactNumberInfo {
902962 /// Only precision information, e.g. `DECIMAL(10)`
903963 Precision ( u64 ) ,
904964 /// Precision and scale information, e.g. `DECIMAL(10,2)`
905- PrecisionAndScale ( u64 , u64 ) ,
965+ PrecisionAndScale ( u64 , i64 ) ,
906966}
907967
908968impl fmt:: Display for ExactNumberInfo {
0 commit comments