@@ -1014,12 +1014,7 @@ pub enum Expr {
10141014 /// A constant of form `<data_type> 'value'`.
10151015 /// This can represent ANSI SQL `DATE`, `TIME`, and `TIMESTAMP` literals (such as `DATE '2020-01-01'`),
10161016 /// as well as constants of other types (a non-standard PostgreSQL extension).
1017- TypedString {
1018- data_type : DataType ,
1019- /// The value of the constant.
1020- /// Hint: you can unwrap the string value using `value.into_string()`.
1021- value : ValueWithSpan ,
1022- } ,
1017+ TypedString ( TypedString ) ,
10231018 /// Scalar function call e.g. `LEFT(foo, 5)`
10241019 Function ( Function ) ,
10251020 /// `CASE [<operand>] WHEN <condition> THEN <result> ... [ELSE <result>] END`
@@ -1734,10 +1729,7 @@ impl fmt::Display for Expr {
17341729 Expr :: Nested ( ast) => write ! ( f, "({ast})" ) ,
17351730 Expr :: Value ( v) => write ! ( f, "{v}" ) ,
17361731 Expr :: Prefixed { prefix, value } => write ! ( f, "{prefix} {value}" ) ,
1737- Expr :: TypedString { data_type, value } => {
1738- write ! ( f, "{data_type}" ) ?;
1739- write ! ( f, " {value}" )
1740- }
1732+ Expr :: TypedString ( ts) => ts. fmt ( f) ,
17411733 Expr :: Function ( fun) => fun. fmt ( f) ,
17421734 Expr :: Case {
17431735 case_token : _,
@@ -7450,6 +7442,52 @@ pub struct DropDomain {
74507442 pub drop_behavior : Option < DropBehavior > ,
74517443}
74527444
7445+ /// A constant of form `<data_type> 'value'`.
7446+ /// This can represent ANSI SQL `DATE`, `TIME`, and `TIMESTAMP` literals (such as `DATE '2020-01-01'`),
7447+ /// as well as constants of other types (a non-standard PostgreSQL extension).
7448+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
7449+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
7450+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
7451+ pub struct TypedString {
7452+ pub data_type : DataType ,
7453+ /// The value of the constant.
7454+ /// Hint: you can unwrap the string value using `value.into_string()`.
7455+ pub value : ValueWithSpan ,
7456+ /// Flags whether this TypedString uses the [ODBC syntax].
7457+ ///
7458+ /// Example:
7459+ /// ```sql
7460+ /// -- An ODBC date literal:
7461+ /// SELECT {d '2025-07-16'}
7462+ /// -- This is equivalent to the standard ANSI SQL literal:
7463+ /// SELECT DATE '2025-07-16'
7464+ ///
7465+ /// [ODBC syntax]: https://learn.microsoft.com/en-us/sql/odbc/reference/develop-app/date-time-and-timestamp-literals?view=sql-server-2017
7466+ pub uses_odbc_syntax : bool ,
7467+ }
7468+
7469+ impl fmt:: Display for TypedString {
7470+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
7471+ let data_type = & self . data_type ;
7472+ let value = & self . value ;
7473+ match self . uses_odbc_syntax {
7474+ false => {
7475+ write ! ( f, "{data_type}" ) ?;
7476+ write ! ( f, " {value}" )
7477+ }
7478+ true => {
7479+ let prefix = match data_type {
7480+ DataType :: Date => "d" ,
7481+ DataType :: Time ( ..) => "t" ,
7482+ DataType :: Timestamp ( ..) => "ts" ,
7483+ _ => "?" ,
7484+ } ;
7485+ write ! ( f, "{{{prefix} {value}}}" )
7486+ }
7487+ }
7488+ }
7489+ }
7490+
74537491/// A function call
74547492#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
74557493#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
0 commit comments