This is an automated email from the ASF dual-hosted git repository.

iffyio pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion-sqlparser-rs.git


The following commit(s) were added to refs/heads/main by this push:
     new 15d8bfea Add support for `SHOW CHARSET` (#1974)
15d8bfea is described below

commit 15d8bfea62726464a3065765f5511af7fa1548f8
Author: etgarperets <etgar.per...@satoricyber.com>
AuthorDate: Tue Jul 29 13:38:07 2025 +0300

    Add support for `SHOW CHARSET` (#1974)
    
    Co-authored-by: Ifeanyi Ubah <ify1...@yahoo.com>
---
 src/ast/mod.rs           | 33 +++++++++++++++++++++++++++++++++
 src/ast/spans.rs         |  1 +
 src/parser/mod.rs        | 12 ++++++++++++
 tests/sqlparser_mysql.rs | 15 +++++++++++++++
 4 files changed, 61 insertions(+)

diff --git a/src/ast/mod.rs b/src/ast/mod.rs
index 42e4d3b0..751da66b 100644
--- a/src/ast/mod.rs
+++ b/src/ast/mod.rs
@@ -3696,6 +3696,12 @@ pub enum Statement {
         history: bool,
         show_options: ShowStatementOptions,
     },
+    // ```sql
+    // SHOW {CHARACTER SET | CHARSET}
+    // ```
+    // [MySQL]:
+    // 
<https://dev.mysql.com/doc/refman/8.4/en/show.html#:~:text=SHOW%20%7BCHARACTER%20SET%20%7C%20CHARSET%7D%20%5Blike_or_where%5D>
+    ShowCharset(ShowCharset),
     /// ```sql
     /// SHOW OBJECTS LIKE 'line%' IN mydb.public
     /// ```
@@ -5680,6 +5686,7 @@ impl fmt::Display for Statement {
                 }
                 Ok(())
             }
+            Statement::ShowCharset(show_stm) => show_stm.fmt(f),
             Statement::StartTransaction {
                 modes,
                 begin: syntax_begin,
@@ -9859,6 +9866,32 @@ impl fmt::Display for ShowStatementIn {
     }
 }
 
+/// A Show Charset statement
+#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
+#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
+#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
+pub struct ShowCharset {
+    /// The statement can be written as `SHOW CHARSET` or `SHOW CHARACTER SET`
+    /// true means CHARSET was used and false means CHARACTER SET was used
+    pub is_shorthand: bool,
+    pub filter: Option<ShowStatementFilter>,
+}
+
+impl fmt::Display for ShowCharset {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        write!(f, "SHOW")?;
+        if self.is_shorthand {
+            write!(f, " CHARSET")?;
+        } else {
+            write!(f, " CHARACTER SET")?;
+        }
+        if self.filter.is_some() {
+            write!(f, " {}", self.filter.as_ref().unwrap())?;
+        }
+        Ok(())
+    }
+}
+
 #[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
 #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
 #[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
diff --git a/src/ast/spans.rs b/src/ast/spans.rs
index 46f7a9ed..8e7011f5 100644
--- a/src/ast/spans.rs
+++ b/src/ast/spans.rs
@@ -477,6 +477,7 @@ impl Spanned for Statement {
             Statement::ShowColumns { .. } => Span::empty(),
             Statement::ShowTables { .. } => Span::empty(),
             Statement::ShowCollation { .. } => Span::empty(),
+            Statement::ShowCharset { .. } => Span::empty(),
             Statement::Use(u) => u.span(),
             Statement::StartTransaction { .. } => Span::empty(),
             Statement::Comment { .. } => Span::empty(),
diff --git a/src/parser/mod.rs b/src/parser/mod.rs
index 3b1db0f6..0ab0ccf4 100644
--- a/src/parser/mod.rs
+++ b/src/parser/mod.rs
@@ -12595,6 +12595,10 @@ impl<'a> Parser<'a> {
             self.parse_show_databases(terse)
         } else if self.parse_keyword(Keyword::SCHEMAS) {
             self.parse_show_schemas(terse)
+        } else if self.parse_keywords(&[Keyword::CHARACTER, Keyword::SET]) {
+            self.parse_show_charset(false)
+        } else if self.parse_keyword(Keyword::CHARSET) {
+            self.parse_show_charset(true)
         } else {
             Ok(Statement::ShowVariable {
                 variable: self.parse_identifiers()?,
@@ -12602,6 +12606,14 @@ impl<'a> Parser<'a> {
         }
     }
 
+    fn parse_show_charset(&mut self, is_shorthand: bool) -> Result<Statement, 
ParserError> {
+        // parse one of keywords
+        Ok(Statement::ShowCharset(ShowCharset {
+            is_shorthand,
+            filter: self.parse_show_statement_filter()?,
+        }))
+    }
+
     fn parse_show_databases(&mut self, terse: bool) -> Result<Statement, 
ParserError> {
         let history = self.parse_keyword(Keyword::HISTORY);
         let show_options = self.parse_show_stmt_options()?;
diff --git a/tests/sqlparser_mysql.rs b/tests/sqlparser_mysql.rs
index 9068ed9c..82b45740 100644
--- a/tests/sqlparser_mysql.rs
+++ b/tests/sqlparser_mysql.rs
@@ -4143,3 +4143,18 @@ fn parse_json_member_of() {
         _ => panic!("Unexpected statement {stmt}"),
     }
 }
+
+#[test]
+fn parse_show_charset() {
+    let res = mysql().verified_stmt("SHOW CHARACTER SET");
+    assert_eq!(
+        res,
+        Statement::ShowCharset(ShowCharset {
+            is_shorthand: false,
+            filter: None
+        })
+    );
+    mysql().verified_stmt("SHOW CHARACTER SET LIKE 'utf8mb4%'");
+    mysql().verified_stmt("SHOW CHARSET WHERE charset = 'utf8mb4%'");
+    mysql().verified_stmt("SHOW CHARSET LIKE 'utf8mb4%'");
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@datafusion.apache.org
For additional commands, e-mail: commits-h...@datafusion.apache.org

Reply via email to