iffyio commented on code in PR #1953:
URL: 
https://github.com/apache/datafusion-sqlparser-rs/pull/1953#discussion_r2218924602


##########
src/ast/mod.rs:
##########
@@ -7397,6 +7389,49 @@ pub struct DropDomain {
     pub drop_behavior: Option<DropBehavior>,
 }
 
+/// A constant of form `<data_type> 'value'`.
+/// This can represent ANSI SQL `DATE`, `TIME`, and `TIMESTAMP` literals (such 
as `DATE '2020-01-01'`),
+/// as well as constants of other types (a non-standard PostgreSQL extension).
+#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
+#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
+#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
+pub struct TypedString {
+    pub data_type: DataType,
+    /// The value of the constant.
+    /// Hint: you can unwrap the string value using `value.into_string()`.
+    pub value: ValueWithSpan,
+    /// Flags whether this TypedString uses the [ODBC syntax].
+    ///
+    /// Example:
+    /// ```sql
+    /// -- An ODBC date literal:
+    /// SELECT {d '2025-07-16'}
+    /// -- This is equivalent to the standard ANSI SQL literal:
+    /// SELECT DATE '2025-07-16'
+    ///
+    /// [ODBC syntax]: 
https://learn.microsoft.com/en-us/sql/odbc/reference/develop-app/date-time-and-timestamp-literals?view=sql-server-2017
+    pub uses_odbc_syntax: bool,
+}
+
+impl fmt::Display for TypedString {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        let data_type = &self.data_type;
+        let value = &self.value;
+        match self.uses_odbc_syntax {
+            false => {
+                write!(f, "{data_type}")?;
+                write!(f, " {value}")
+            }
+            true => match data_type {
+                DataType::Date => write!(f, "{{d {value}}}"),
+                DataType::Time(..) => write!(f, "{{t {value}}}"),
+                DataType::Timestamp(..) => write!(f, "{{ts {value}}}"),
+                _ => write!(f, "{{? {value}}}"),
+            },

Review Comment:
   ```suggestion
               true => {
                   let dt = match data_type {
                       DataType::Date => "d",
                       DataType::Time(..) => "t"
                       DataType::Timestamp(..) => "ts",
                   };
                   write!("{{ {dt} }}")
               },
   ```
   I think this branch could be simplified to something like above?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to