Mysql: Add SRID column option (#1852)

This commit is contained in:
Mohamed Abdeen 2025-05-23 06:09:05 +01:00 committed by GitHub
parent 05d7ffb1d5
commit bf2b72fbe0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 21 additions and 0 deletions

View file

@ -1758,6 +1758,13 @@ pub enum ColumnOption {
/// ```
/// [Snowflake]: https://docs.snowflake.com/en/sql-reference/sql/create-table
Tags(TagsColumnOption),
/// MySQL specific: Spatial reference identifier
/// Syntax:
/// ```sql
/// CREATE TABLE geom (g GEOMETRY NOT NULL SRID 4326);
/// ```
/// [MySQL]: https://dev.mysql.com/doc/refman/8.4/en/creating-spatial-indexes.html
Srid(Box<Expr>),
}
impl fmt::Display for ColumnOption {
@ -1873,6 +1880,9 @@ impl fmt::Display for ColumnOption {
Tags(tags) => {
write!(f, "{tags}")
}
Srid(srid) => {
write!(f, "SRID {srid}")
}
}
}
}

View file

@ -871,6 +871,7 @@ impl Spanned for ColumnOption {
ColumnOption::OnConflict(..) => Span::empty(),
ColumnOption::Policy(..) => Span::empty(),
ColumnOption::Tags(..) => Span::empty(),
ColumnOption::Srid(..) => Span::empty(),
}
}
}

View file

@ -844,6 +844,7 @@ define_keywords!(
SQLSTATE,
SQLWARNING,
SQRT,
SRID,
STABLE,
STAGE,
START,

View file

@ -7754,6 +7754,10 @@ impl<'a> Parser<'a> {
&& dialect_of!(self is MySqlDialect | SQLiteDialect | DuckDbDialect | GenericDialect)
{
self.parse_optional_column_option_as()
} else if self.parse_keyword(Keyword::SRID)
&& dialect_of!(self is MySqlDialect | GenericDialect)
{
Ok(Some(ColumnOption::Srid(Box::new(self.parse_expr()?))))
} else if self.parse_keyword(Keyword::IDENTITY)
&& dialect_of!(self is MsSqlDialect | GenericDialect)
{

View file

@ -3745,6 +3745,11 @@ fn parse_begin_without_transaction() {
mysql().verified_stmt("BEGIN");
}
#[test]
fn parse_geometric_types_srid_option() {
mysql_and_generic().verified_stmt("CREATE TABLE t (a geometry SRID 4326)");
}
#[test]
fn parse_double_precision() {
mysql().verified_stmt("CREATE TABLE foo (bar DOUBLE)");