Skip to content

Commit 685d76c

Browse files
MySQL: Add support for INVISIBLE columns
This commit adds support for INVISIBLE columns in MySQL dialect.
1 parent f642dd5 commit 685d76c

File tree

5 files changed

+47
-0
lines changed

5 files changed

+47
-0
lines changed

src/ast/ddl.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1911,6 +1911,13 @@ pub enum ColumnOption {
19111911
/// ```
19121912
/// [MySQL]: https://dev.mysql.com/doc/refman/8.4/en/creating-spatial-indexes.html
19131913
Srid(Box<Expr>),
1914+
/// MySQL specific: Column is invisible via SELECT *
1915+
/// Syntax:
1916+
/// ```sql
1917+
/// CREATE TABLE t (foo INT, bar INT INVISIBLE);
1918+
/// ```
1919+
/// [MySQL]: https://dev.mysql.com/doc/refman/8.4/en/invisible-columns.html
1920+
Invisible,
19141921
}
19151922

19161923
impl fmt::Display for ColumnOption {
@@ -2029,6 +2036,9 @@ impl fmt::Display for ColumnOption {
20292036
Srid(srid) => {
20302037
write!(f, "SRID {srid}")
20312038
}
2039+
Invisible => {
2040+
write!(f, "INVISIBLE")
2041+
}
20322042
}
20332043
}
20342044
}

src/ast/spans.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,7 @@ impl Spanned for ColumnOption {
918918
ColumnOption::Policy(..) => Span::empty(),
919919
ColumnOption::Tags(..) => Span::empty(),
920920
ColumnOption::Srid(..) => Span::empty(),
921+
ColumnOption::Invisible => Span::empty(),
921922
}
922923
}
923924
}

src/keywords.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ define_keywords!(
499499
INTERSECTION,
500500
INTERVAL,
501501
INTO,
502+
INVISIBLE,
502503
INVOKER,
503504
IO,
504505
IS,

src/parser/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8144,6 +8144,11 @@ impl<'a> Parser<'a> {
81448144
Keyword::REPLACE,
81458145
])?,
81468146
)))
8147+
} else if dialect_of!(self is MySqlDialect | GenericDialect)
8148+
&& self.parse_keyword(Keyword::INVISIBLE)
8149+
{
8150+
// Support INVISIBLE for MySQL
8151+
Ok(Some(ColumnOption::Invisible))
81478152
} else {
81488153
Ok(None)
81498154
}

tests/sqlparser_mysql.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4247,3 +4247,33 @@ fn test_create_index_options() {
42474247
"CREATE INDEX idx_name ON t(c1, c2) USING BTREE LOCK = EXCLUSIVE ALGORITHM = DEFAULT",
42484248
);
42494249
}
4250+
4251+
#[test]
4252+
fn parse_invisible_column() {
4253+
mysql().verified_stmt("CREATE TABLE t (foo INT, bar INT INVISIBLE)");
4254+
mysql().verified_stmt("ALTER TABLE t ADD COLUMN bar INT INVISIBLE");
4255+
let stmt = mysql().verified_stmt("CREATE TABLE t (foo INT, bar INT INVISIBLE)");
4256+
match stmt {
4257+
Statement::CreateTable(CreateTable { columns, .. }) => {
4258+
assert_eq!(
4259+
columns,
4260+
vec![
4261+
ColumnDef {
4262+
name: "foo".into(),
4263+
data_type: DataType::Int(None),
4264+
options: vec![],
4265+
},
4266+
ColumnDef {
4267+
name: "bar".into(),
4268+
data_type: DataType::Int(None),
4269+
options: vec![ColumnOptionDef {
4270+
name: None,
4271+
option: ColumnOption::Invisible,
4272+
},],
4273+
}
4274+
]
4275+
);
4276+
}
4277+
_ => panic!("Unexpected statement {stmt}"),
4278+
}
4279+
}

0 commit comments

Comments
 (0)