Skip to content

Commit f98ad05

Browse files
committed
Support SHOW COLUMNS FROM tbl FROM db
1 parent 231370a commit f98ad05

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

src/parser.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3732,10 +3732,16 @@ impl<'a> Parser<'a> {
37323732
let full = self.parse_keyword(Keyword::FULL);
37333733
self.expect_one_of_keywords(&[Keyword::COLUMNS, Keyword::FIELDS])?;
37343734
self.expect_one_of_keywords(&[Keyword::FROM, Keyword::IN])?;
3735-
let table_name = self.parse_object_name()?;
3736-
// MySQL also supports FROM <database> here. In other words, MySQL
3737-
// allows both FROM <table> FROM <database> and FROM <database>.<table>,
3738-
// while we only support the latter for now.
3735+
let object_name = self.parse_object_name()?;
3736+
let table_name = match self.parse_one_of_keywords(&[Keyword::FROM, Keyword::IN]) {
3737+
Some(_) => {
3738+
let db_name = vec![self.parse_identifier()?];
3739+
let ObjectName(table_name) = object_name;
3740+
let object_name = db_name.into_iter().chain(table_name.into_iter()).collect();
3741+
ObjectName(object_name)
3742+
}
3743+
None => object_name,
3744+
};
37393745
let filter = self.parse_show_statement_filter()?;
37403746
Ok(Statement::ShowColumns {
37413747
extended,

tests/sqlparser_mysql.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,10 @@ fn parse_show_columns() {
110110
.one_statement_parses_to("SHOW COLUMNS IN mytable", "SHOW COLUMNS FROM mytable");
111111
mysql_and_generic()
112112
.one_statement_parses_to("SHOW FIELDS IN mytable", "SHOW COLUMNS FROM mytable");
113-
114-
// unhandled things are truly unhandled
115-
match mysql_and_generic().parse_sql_statements("SHOW COLUMNS FROM mytable FROM mydb") {
116-
Err(_) => {}
117-
Ok(val) => panic!("unexpected successful parse: {:?}", val),
118-
}
113+
mysql_and_generic().one_statement_parses_to(
114+
"SHOW COLUMNS FROM mytable FROM mydb",
115+
"SHOW COLUMNS FROM mydb.mytable",
116+
);
119117
}
120118

121119
#[test]

0 commit comments

Comments
 (0)