From 9391ba830ec6de78a20869afc03c9b0995febcc1 Mon Sep 17 00:00:00 2001 From: slopgobblercobbler Date: Sat, 31 Oct 2026 20:00:21 +0100 Subject: [PATCH] Fix quotes when displaying SHOW ... ILIKE patterns In `ShowStatementFilter::ILike`, the format string omitted single quotes around the escaped string pattern, causing statements like `SHOW DATABASES ILIKE '%DE%'` to format as `SHOW DATABASES ILIKE %DE%`, failing to reparse when the pattern is not an identifier. Closes #2759. --- src/ast/mod.rs | 2 +- tests/sqlparser_clickhouse.rs | 6 ++++++ tests/sqlparser_common.rs | 5 +++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/ast/mod.rs b/src/ast/mod.rs index 0b0893d7e4..6140c92d4a 100644 --- a/src/ast/mod.rs +++ b/src/ast/mod.rs @@ -9501,7 +9501,7 @@ impl fmt::Display for ShowStatementFilter { use ShowStatementFilter::*; match self { Like(pattern) => write!(f, "LIKE '{}'", value::escape_single_quote_string(pattern)), - ILike(pattern) => write!(f, "ILIKE {}", value::escape_single_quote_string(pattern)), + ILike(pattern) => write!(f, "ILIKE '{}'", value::escape_single_quote_string(pattern)), Where(expr) => write!(f, "WHERE {expr}"), NoKeyword(pattern) => write!(f, "'{}'", value::escape_single_quote_string(pattern)), } diff --git a/tests/sqlparser_clickhouse.rs b/tests/sqlparser_clickhouse.rs index 3e6fe93270..bb808c9018 100644 --- a/tests/sqlparser_clickhouse.rs +++ b/tests/sqlparser_clickhouse.rs @@ -2367,3 +2367,9 @@ fn parse_create_table_engine_name_quoting() { clickhouse_and_generic().verified_stmt("CREATE TABLE t (a INT) ENGINE = ``"); clickhouse().verified_stmt("CREATE TABLE t (a INT) ENGINE = MergeTree"); } + +#[test] +fn test_show_databases_tables_ilike() { + clickhouse().verified_stmt("SHOW DATABASES ILIKE '%DE%'"); + clickhouse().verified_stmt("SHOW TABLES ILIKE '%abc%'"); +} diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs index 7627f39185..baa426d24e 100644 --- a/tests/sqlparser_common.rs +++ b/tests/sqlparser_common.rs @@ -16547,8 +16547,13 @@ fn test_show_dbs_schemas_tables_views() { // LIKE option (infix/suffix) let stmts = vec![ "SHOW CATALOGS LIKE '%abc'", + "SHOW CATALOGS ILIKE '%abc'", "SHOW DATABASES LIKE '%abc'", + "SHOW DATABASES ILIKE '%abc'", "SHOW SCHEMAS LIKE '%abc'", + "SHOW SCHEMAS ILIKE '%abc'", + "SHOW DATABASES LIKE 'a''b'", + "SHOW DATABASES ILIKE 'a''b'", ]; for stmt in stmts { all_dialects_where(|d| d.supports_show_like_before_in()).verified_stmt(stmt);