File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1758,6 +1758,13 @@ pub enum ColumnOption {
17581758 /// ```
17591759 /// [Snowflake]: https://docs.snowflake.com/en/sql-reference/sql/create-table
17601760 Tags ( TagsColumnOption ) ,
1761+ /// MySQL specific: Spatial reference identifier
1762+ /// Syntax:
1763+ /// ```sql
1764+ /// CREATE TABLE geom (g GEOMETRY NOT NULL SRID 4326);
1765+ /// ```
1766+ /// [MySQL]: https://dev.mysql.com/doc/refman/8.4/en/creating-spatial-indexes.html
1767+ Srid ( Expr ) ,
17611768}
17621769
17631770impl fmt:: Display for ColumnOption {
@@ -1873,6 +1880,9 @@ impl fmt::Display for ColumnOption {
18731880 Tags ( tags) => {
18741881 write ! ( f, "{tags}" )
18751882 }
1883+ Srid ( srid) => {
1884+ write ! ( f, "SRID {srid}" )
1885+ }
18761886 }
18771887 }
18781888}
Original file line number Diff line number Diff line change @@ -871,6 +871,7 @@ impl Spanned for ColumnOption {
871871 ColumnOption :: OnConflict ( ..) => Span :: empty ( ) ,
872872 ColumnOption :: Policy ( ..) => Span :: empty ( ) ,
873873 ColumnOption :: Tags ( ..) => Span :: empty ( ) ,
874+ ColumnOption :: Srid ( ..) => Span :: empty ( ) ,
874875 }
875876 }
876877}
Original file line number Diff line number Diff line change @@ -844,6 +844,7 @@ define_keywords!(
844844 SQLSTATE ,
845845 SQLWARNING ,
846846 SQRT ,
847+ SRID ,
847848 STABLE ,
848849 STAGE ,
849850 START ,
Original file line number Diff line number Diff line change @@ -7754,6 +7754,10 @@ impl<'a> Parser<'a> {
77547754 && dialect_of!(self is MySqlDialect | SQLiteDialect | DuckDbDialect | GenericDialect)
77557755 {
77567756 self.parse_optional_column_option_as()
7757+ } else if self.parse_keyword(Keyword::SRID)
7758+ && dialect_of!(self is MySqlDialect | GenericDialect)
7759+ {
7760+ Ok(Some(ColumnOption::Srid(self.parse_expr()?)))
77577761 } else if self.parse_keyword(Keyword::IDENTITY)
77587762 && dialect_of!(self is MsSqlDialect | GenericDialect)
77597763 {
@@ -16577,6 +16581,20 @@ mod tests {
1657716581 }
1657816582 }
1657916583
16584+ #[test]
16585+ fn test_mysql_srid_create_table() {
16586+ let sql = r#"CREATE TABLE t (a geometry SRID 4326)"#;
16587+ let ast: Vec<Statement> = Parser::parse_sql(&MySqlDialect {}, sql).unwrap();
16588+
16589+ assert_eq!(ast.len(), 1);
16590+ if let Statement::CreateTable(v) = &ast[0] {
16591+ assert_eq!(
16592+ v.columns[0].options[0].option,
16593+ ColumnOption::Srid(Expr::value(Value::Number("4326".to_string(), false)))
16594+ );
16595+ }
16596+ }
16597+
1658016598 #[test]
1658116599 fn test_replace_into_placeholders() {
1658216600 let sql = "REPLACE INTO t (a) VALUES (&a)";
You can’t perform that action at this time.
0 commit comments