Skip to content

Commit 07342d5

Browse files
authored
Support parsing multiple show variables. (apache#290)
* feat: support parsing multiple show variables. * fix: fix fmt error
1 parent f40955e commit 07342d5

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

src/ast/mod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ pub enum Statement {
637637
/// SHOW <variable>
638638
///
639639
/// Note: this is a PostgreSQL-specific statement.
640-
ShowVariable { variable: Ident },
640+
ShowVariable { variable: Vec<Ident> },
641641
/// SHOW COLUMNS
642642
///
643643
/// Note: this is a MySQL-specific statement.
@@ -1136,7 +1136,13 @@ impl fmt::Display for Statement {
11361136
value = display_comma_separated(value)
11371137
)
11381138
}
1139-
Statement::ShowVariable { variable } => write!(f, "SHOW {}", variable),
1139+
Statement::ShowVariable { variable } => {
1140+
write!(f, "SHOW")?;
1141+
if !variable.is_empty() {
1142+
write!(f, " {}", display_separated(variable, " "))?;
1143+
}
1144+
Ok(())
1145+
}
11401146
Statement::ShowColumns {
11411147
extended,
11421148
full,

src/parser.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2043,6 +2043,19 @@ impl<'a> Parser<'a> {
20432043
Ok(ObjectName(idents))
20442044
}
20452045

2046+
/// Parse identifiers
2047+
pub fn parse_identifiers(&mut self) -> Result<Vec<Ident>, ParserError> {
2048+
let mut idents = vec![];
2049+
loop {
2050+
match self.next_token() {
2051+
Token::Word(w) => idents.push(w.to_ident()),
2052+
Token::EOF => break,
2053+
_ => {}
2054+
}
2055+
}
2056+
Ok(idents)
2057+
}
2058+
20462059
/// Parse a simple one-word identifier (possibly quoted, possibly a keyword)
20472060
pub fn parse_identifier(&mut self) -> Result<Ident, ParserError> {
20482061
match self.next_token() {
@@ -2439,7 +2452,7 @@ impl<'a> Parser<'a> {
24392452
self.parse_show_columns()
24402453
} else {
24412454
Ok(Statement::ShowVariable {
2442-
variable: self.parse_identifier()?,
2455+
variable: self.parse_identifiers()?,
24432456
})
24442457
}
24452458
}

tests/sqlparser_postgres.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -443,19 +443,19 @@ fn parse_set() {
443443

444444
#[test]
445445
fn parse_show() {
446-
let stmt = pg_and_generic().verified_stmt("SHOW a");
446+
let stmt = pg_and_generic().verified_stmt("SHOW a a");
447447
assert_eq!(
448448
stmt,
449449
Statement::ShowVariable {
450-
variable: "a".into()
450+
variable: vec!["a".into(), "a".into()]
451451
}
452452
);
453453

454-
let stmt = pg_and_generic().verified_stmt("SHOW ALL");
454+
let stmt = pg_and_generic().verified_stmt("SHOW ALL ALL");
455455
assert_eq!(
456456
stmt,
457457
Statement::ShowVariable {
458-
variable: "ALL".into()
458+
variable: vec!["ALL".into(), "ALL".into()]
459459
}
460460
)
461461
}

0 commit comments

Comments
 (0)