Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -1911,6 +1911,13 @@ pub enum ColumnOption {
/// ```
/// [MySQL]: https://dev.mysql.com/doc/refman/8.4/en/creating-spatial-indexes.html
Srid(Box<Expr>),
/// MySQL specific: Column is invisible via SELECT *
/// Syntax:
/// ```sql
/// CREATE TABLE t (foo INT, bar INT INVISIBLE);
/// ```
/// [MySQL]: https://dev.mysql.com/doc/refman/8.4/en/invisible-columns.html
Invisible,
}

impl fmt::Display for ColumnOption {
Expand Down Expand Up @@ -2029,6 +2036,9 @@ impl fmt::Display for ColumnOption {
Srid(srid) => {
write!(f, "SRID {srid}")
}
Invisible => {
write!(f, "INVISIBLE")
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/ast/spans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,7 @@ impl Spanned for ColumnOption {
ColumnOption::Policy(..) => Span::empty(),
ColumnOption::Tags(..) => Span::empty(),
ColumnOption::Srid(..) => Span::empty(),
ColumnOption::Invisible => 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 @@ -499,6 +499,7 @@ define_keywords!(
INTERSECTION,
INTERVAL,
INTO,
INVISIBLE,
INVOKER,
IO,
IS,
Expand Down
2 changes: 2 additions & 0 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8144,6 +8144,8 @@ impl<'a> Parser<'a> {
Keyword::REPLACE,
])?,
)))
} else if self.parse_keyword(Keyword::INVISIBLE) {
Ok(Some(ColumnOption::Invisible))
} else {
Ok(None)
}
Expand Down
30 changes: 30 additions & 0 deletions tests/sqlparser_mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4247,3 +4247,33 @@ fn test_create_index_options() {
"CREATE INDEX idx_name ON t(c1, c2) USING BTREE LOCK = EXCLUSIVE ALGORITHM = DEFAULT",
);
}

#[test]
fn parse_invisible_column() {
mysql().verified_stmt("CREATE TABLE t (foo INT, bar INT INVISIBLE)");
mysql().verified_stmt("ALTER TABLE t ADD COLUMN bar INT INVISIBLE");
let stmt = mysql().verified_stmt("CREATE TABLE t (foo INT, bar INT INVISIBLE)");
match stmt {
Statement::CreateTable(CreateTable { columns, .. }) => {
assert_eq!(
columns,
vec![
ColumnDef {
name: "foo".into(),
data_type: DataType::Int(None),
options: vec![],
},
ColumnDef {
name: "bar".into(),
data_type: DataType::Int(None),
options: vec![ColumnOptionDef {
name: None,
option: ColumnOption::Invisible,
},],
}
]
);
}
_ => panic!("Unexpected statement {stmt}"),
}
}
Loading