Skip to content

Commit 71c3ec0

Browse files
authored
Support SHOW COLUMNS FROM tbl FROM db (apache#562)
1 parent e2b9437 commit 71c3ec0

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
@@ -3739,10 +3739,16 @@ impl<'a> Parser<'a> {
37393739
let full = self.parse_keyword(Keyword::FULL);
37403740
self.expect_one_of_keywords(&[Keyword::COLUMNS, Keyword::FIELDS])?;
37413741
self.expect_one_of_keywords(&[Keyword::FROM, Keyword::IN])?;
3742-
let table_name = self.parse_object_name()?;
3743-
// MySQL also supports FROM <database> here. In other words, MySQL
3744-
// allows both FROM <table> FROM <database> and FROM <database>.<table>,
3745-
// while we only support the latter for now.
3742+
let object_name = self.parse_object_name()?;
3743+
let table_name = match self.parse_one_of_keywords(&[Keyword::FROM, Keyword::IN]) {
3744+
Some(_) => {
3745+
let db_name = vec![self.parse_identifier()?];
3746+
let ObjectName(table_name) = object_name;
3747+
let object_name = db_name.into_iter().chain(table_name.into_iter()).collect();
3748+
ObjectName(object_name)
3749+
}
3750+
None => object_name,
3751+
};
37463752
let filter = self.parse_show_statement_filter()?;
37473753
Ok(Statement::ShowColumns {
37483754
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)