Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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: 8 additions & 2 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ pub enum Statement {
/// SHOW <variable>
///
/// Note: this is a PostgreSQL-specific statement.
ShowVariable { variable: Ident },
ShowVariable { variable: Vec<Ident> },
/// SHOW COLUMNS
///
/// Note: this is a MySQL-specific statement.
Expand Down Expand Up @@ -1136,7 +1136,13 @@ impl fmt::Display for Statement {
value = display_comma_separated(value)
)
}
Statement::ShowVariable { variable } => write!(f, "SHOW {}", variable),
Statement::ShowVariable { variable } => {
write!(f, "SHOW")?;
if !variable.is_empty() {
write!(f, " {}", display_separated(variable, " "))?;
}
Ok(())
}
Statement::ShowColumns {
extended,
full,
Expand Down
15 changes: 14 additions & 1 deletion src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2043,6 +2043,19 @@ impl<'a> Parser<'a> {
Ok(ObjectName(idents))
}

/// Parse identifiers
pub fn parse_identifiers(&mut self) -> Result<Vec<Ident>, ParserError> {
let mut idents = vec![];
loop {
match self.next_token() {
Token::Word(w) => idents.push(w.to_ident()),
Token::EOF => break,
_ => {}
}
}
Ok(idents)
}
Comment on lines +2047 to +2057
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is SHOW (without any variable) valid SQL? This code would return Ok(vec![]) for the SQL code SHOW, correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes


/// Parse a simple one-word identifier (possibly quoted, possibly a keyword)
pub fn parse_identifier(&mut self) -> Result<Ident, ParserError> {
match self.next_token() {
Expand Down Expand Up @@ -2439,7 +2452,7 @@ impl<'a> Parser<'a> {
self.parse_show_columns()
} else {
Ok(Statement::ShowVariable {
variable: self.parse_identifier()?,
variable: self.parse_identifiers()?,
})
}
}
Expand Down
8 changes: 4 additions & 4 deletions tests/sqlparser_postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,19 +443,19 @@ fn parse_set() {

#[test]
fn parse_show() {
let stmt = pg_and_generic().verified_stmt("SHOW a");
let stmt = pg_and_generic().verified_stmt("SHOW a a");
assert_eq!(
stmt,
Statement::ShowVariable {
variable: "a".into()
variable: vec!["a".into(), "a".into()]
}
);

let stmt = pg_and_generic().verified_stmt("SHOW ALL");
let stmt = pg_and_generic().verified_stmt("SHOW ALL ALL");
assert_eq!(
stmt,
Statement::ShowVariable {
variable: "ALL".into()
variable: vec!["ALL".into(), "ALL".into()]
}
)
}
Expand Down