Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/ast/ddl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -1873,6 +1880,9 @@ impl fmt::Display for ColumnOption {
Tags(tags) => {
write!(f, "{tags}")
}
Srid(srid) => {
write!(f, "SRID {srid}")
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/ast/spans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,7 @@ impl Spanned for ColumnOption {
ColumnOption::OnConflict(..) => Span::empty(),
ColumnOption::Policy(..) => Span::empty(),
ColumnOption::Tags(..) => Span::empty(),
ColumnOption::Srid(..) => Span::empty(),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/keywords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,7 @@ define_keywords!(
SQLSTATE,
SQLWARNING,
SQRT,
SRID,
STABLE,
STAGE,
START,
Expand Down
4 changes: 4 additions & 0 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
5 changes: 5 additions & 0 deletions tests/sqlparser_mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)");
Expand Down