MySQL: Allow optional SIGNED suffix on integer data types (#1985)

This commit is contained in:
Michael Victor Zink 2025-08-01 03:33:43 -07:00 committed by GitHub
parent 3d2db8c69b
commit f5f51eb6f1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 83 additions and 0 deletions

View file

@ -183,4 +183,8 @@ impl Dialect for GenericDialect {
fn supports_select_wildcard_exclude(&self) -> bool {
true
}
fn supports_data_type_signed_suffix(&self) -> bool {
true
}
}

View file

@ -1136,6 +1136,18 @@ pub trait Dialect: Debug + Any {
fn supports_notnull_operator(&self) -> bool {
false
}
/// Returns true if this dialect allows an optional `SIGNED` suffix after integer data types.
///
/// Example:
/// ```sql
/// CREATE TABLE t (i INT(20) SIGNED);
/// ```
///
/// Note that this is canonicalized to `INT(20)`.
fn supports_data_type_signed_suffix(&self) -> bool {
false
}
}
/// This represents the operators for which precedence must be defined

View file

@ -154,6 +154,10 @@ impl Dialect for MySqlDialect {
fn supports_comma_separated_set_assignments(&self) -> bool {
true
}
fn supports_data_type_signed_suffix(&self) -> bool {
true
}
}
/// `LOCK TABLES`

View file

@ -9848,6 +9848,9 @@ impl<'a> Parser<'a> {
if self.parse_keyword(Keyword::UNSIGNED) {
Ok(DataType::TinyIntUnsigned(optional_precision?))
} else {
if dialect.supports_data_type_signed_suffix() {
let _ = self.parse_keyword(Keyword::SIGNED);
}
Ok(DataType::TinyInt(optional_precision?))
}
}
@ -9864,6 +9867,9 @@ impl<'a> Parser<'a> {
if self.parse_keyword(Keyword::UNSIGNED) {
Ok(DataType::SmallIntUnsigned(optional_precision?))
} else {
if dialect.supports_data_type_signed_suffix() {
let _ = self.parse_keyword(Keyword::SIGNED);
}
Ok(DataType::SmallInt(optional_precision?))
}
}
@ -9872,6 +9878,9 @@ impl<'a> Parser<'a> {
if self.parse_keyword(Keyword::UNSIGNED) {
Ok(DataType::MediumIntUnsigned(optional_precision?))
} else {
if dialect.supports_data_type_signed_suffix() {
let _ = self.parse_keyword(Keyword::SIGNED);
}
Ok(DataType::MediumInt(optional_precision?))
}
}
@ -9880,6 +9889,9 @@ impl<'a> Parser<'a> {
if self.parse_keyword(Keyword::UNSIGNED) {
Ok(DataType::IntUnsigned(optional_precision?))
} else {
if dialect.supports_data_type_signed_suffix() {
let _ = self.parse_keyword(Keyword::SIGNED);
}
Ok(DataType::Int(optional_precision?))
}
}
@ -9909,6 +9921,9 @@ impl<'a> Parser<'a> {
if self.parse_keyword(Keyword::UNSIGNED) {
Ok(DataType::IntegerUnsigned(optional_precision?))
} else {
if dialect.supports_data_type_signed_suffix() {
let _ = self.parse_keyword(Keyword::SIGNED);
}
Ok(DataType::Integer(optional_precision?))
}
}
@ -9917,6 +9932,9 @@ impl<'a> Parser<'a> {
if self.parse_keyword(Keyword::UNSIGNED) {
Ok(DataType::BigIntUnsigned(optional_precision?))
} else {
if dialect.supports_data_type_signed_suffix() {
let _ = self.parse_keyword(Keyword::SIGNED);
}
Ok(DataType::BigInt(optional_precision?))
}
}