Skip to content

Support SHOW FUNCTIONS #620

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 26, 2022
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
11 changes: 11 additions & 0 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,10 @@ pub enum Statement {
///
/// Note: this is a MySQL-specific statement.
SetNamesDefault {},
/// SHOW FUNCTIONS
///
/// Note: this is a Presto-specific statement.
ShowFunctions { filter: Option<ShowStatementFilter> },
/// SHOW <variable>
///
/// Note: this is a PostgreSQL-specific statement.
Expand Down Expand Up @@ -2033,6 +2037,13 @@ impl fmt::Display for Statement {
}
Ok(())
}
Statement::ShowFunctions { filter } => {
write!(f, "SHOW FUNCTIONS")?;
if let Some(filter) = filter {
write!(f, " {}", filter)?;
}
Ok(())
}
Statement::Use { db_name } => {
write!(f, "USE {}", db_name)?;
Ok(())
Expand Down
1 change: 1 addition & 0 deletions src/keywords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ define_keywords!(
FROM,
FULL,
FUNCTION,
FUNCTIONS,
FUSION,
GET,
GLOBAL,
Expand Down
7 changes: 7 additions & 0 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3854,6 +3854,8 @@ impl<'a> Parser<'a> {
Ok(self.parse_show_columns(extended, full)?)
} else if self.parse_keyword(Keyword::TABLES) {
Ok(self.parse_show_tables(extended, full)?)
} else if self.parse_keyword(Keyword::FUNCTIONS) {
Ok(self.parse_show_functions()?)
} else if extended || full {
Err(ParserError::ParserError(
"EXTENDED/FULL are not supported with this type of SHOW query".to_string(),
Expand Down Expand Up @@ -3945,6 +3947,11 @@ impl<'a> Parser<'a> {
})
}

pub fn parse_show_functions(&mut self) -> Result<Statement, ParserError> {
let filter = self.parse_show_statement_filter()?;
Ok(Statement::ShowFunctions { filter })
}

pub fn parse_show_collation(&mut self) -> Result<Statement, ParserError> {
let filter = self.parse_show_statement_filter()?;
Ok(Statement::ShowCollation { filter })
Expand Down
10 changes: 10 additions & 0 deletions tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5569,3 +5569,13 @@ fn parse_cursor() {
_ => unreachable!(),
}
}

#[test]
fn parse_show_functions() {
assert_eq!(
verified_stmt("SHOW FUNCTIONS LIKE 'pattern'"),
Statement::ShowFunctions {
filter: Some(ShowStatementFilter::Like("pattern".into())),
}
);
}