Support SHOW FUNCTIONS (#620)

* support SHOW FUNCTIONS

* Update keywords.rs

* Update mod.rs

* Update sqlparser_common.rs

* Fix CI issues
This commit is contained in:
Justin Joyce 2022-09-26 07:33:53 +01:00 committed by GitHub
parent fccae77c5e
commit 495ab59aad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 0 deletions

View file

@ -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.
@ -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(())

View file

@ -250,6 +250,7 @@ define_keywords!(
FROM,
FULL,
FUNCTION,
FUNCTIONS,
FUSION,
GET,
GLOBAL,

View file

@ -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(),
@ -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 })

View file

@ -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())),
}
);
}