File tree Expand file tree Collapse file tree 4 files changed +30
-0
lines changed
Expand file tree Collapse file tree 4 files changed +30
-0
lines changed 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 @@ -7748,6 +7748,10 @@ impl<'a> Parser<'a> {
77487748 && dialect_of!(self is MySqlDialect | SQLiteDialect | DuckDbDialect | GenericDialect)
77497749 {
77507750 self.parse_optional_column_option_as()
7751+ } else if self.parse_keyword(Keyword::SRID)
7752+ && dialect_of!(self is MySqlDialect | GenericDialect)
7753+ {
7754+ Ok(Some(ColumnOption::Srid(self.parse_expr()?)))
77517755 } else if self.parse_keyword(Keyword::IDENTITY)
77527756 && dialect_of!(self is MsSqlDialect | GenericDialect)
77537757 {
@@ -16571,6 +16575,20 @@ mod tests {
1657116575 }
1657216576 }
1657316577
16578+ #[test]
16579+ fn test_mysql_srid_create_table() {
16580+ let sql = r#"CREATE TABLE t (a geometry SRID 4326)"#;
16581+ let ast: Vec<Statement> = Parser::parse_sql(&MySqlDialect {}, sql).unwrap();
16582+
16583+ assert_eq!(ast.len(), 1);
16584+ if let Statement::CreateTable(v) = &ast[0] {
16585+ assert_eq!(
16586+ v.columns[0].options[0].option,
16587+ ColumnOption::Srid(Expr::value(Value::Number("4326".to_string(), false)))
16588+ );
16589+ }
16590+ }
16591+
1657416592 #[test]
1657516593 fn test_replace_into_placeholders() {
1657616594 let sql = "REPLACE INTO t (a) VALUES (&a)";
You can’t perform that action at this time.
0 commit comments