Support for MSSQL CONVERT styles (#1219)

This commit is contained in:
Ifeanyi Ubah 2024-04-30 16:22:13 +02:00 committed by GitHub
parent 6fcf8c9abe
commit 0606024353
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 47 additions and 0 deletions

View file

@ -567,6 +567,10 @@ pub enum Expr {
charset: Option<ObjectName>,
/// whether the target comes before the expr (MSSQL syntax)
target_before_value: bool,
/// How to translate the expression.
///
/// [MSSQL]: https://learn.microsoft.com/en-us/sql/t-sql/functions/cast-and-convert-transact-sql?view=sql-server-ver16#style
styles: Vec<Expr>,
},
/// `CAST` an expression to a different data type e.g. `CAST(foo AS VARCHAR(123))`
Cast {
@ -979,6 +983,7 @@ impl fmt::Display for Expr {
target_before_value,
data_type,
charset,
styles,
} => {
write!(f, "CONVERT(")?;
if let Some(data_type) = data_type {
@ -994,6 +999,9 @@ impl fmt::Display for Expr {
} else {
write!(f, "{expr}") // This should never happen
}?;
if !styles.is_empty() {
write!(f, ", {}", display_comma_separated(styles))?;
}
write!(f, ")")
}
Expr::Cast {