mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-18 04:12:19 +00:00
Add new feature: SHOW DATABASES LIKE
This commit is contained in:
parent
5b0822902b
commit
a3671a15f6
@ -31,7 +31,21 @@ String InterpreterShowTablesQuery::getRewrittenQuery()
|
||||
|
||||
/// SHOW DATABASES
|
||||
if (query.databases)
|
||||
return "SELECT name FROM system.databases";
|
||||
{
|
||||
std::stringstream rewritten_query;
|
||||
rewritten_query << "SELECT name FROM system.databases";
|
||||
|
||||
if (!query.like.empty())
|
||||
{
|
||||
rewritten_query << " WHERE name " << (query.not_like ? "NOT " : "") << "LIKE " << std::quoted(query.like, '\'');
|
||||
}
|
||||
|
||||
if (query.limit_length)
|
||||
rewritten_query << " LIMIT " << query.limit_length;
|
||||
|
||||
DUMP(rewritten_query.str());
|
||||
return rewritten_query.str();
|
||||
}
|
||||
|
||||
/// SHOW CLUSTER/CLUSTERS
|
||||
if (query.clusters)
|
||||
|
@ -18,6 +18,20 @@ void ASTShowTablesQuery::formatQueryImpl(const FormatSettings & settings, Format
|
||||
if (databases)
|
||||
{
|
||||
settings.ostr << (settings.hilite ? hilite_keyword : "") << "SHOW DATABASES" << (settings.hilite ? hilite_none : "");
|
||||
|
||||
if (!like.empty())
|
||||
settings.ostr
|
||||
<< (settings.hilite ? hilite_keyword : "")
|
||||
<< (not_like ? " NOT" : "")
|
||||
<< (case_insensitive_like ? " ILIKE " : " LIKE ")
|
||||
<< (settings.hilite ? hilite_none : "")
|
||||
<< std::quoted(like, '\'');
|
||||
|
||||
if (limit_length)
|
||||
{
|
||||
settings.ostr << (settings.hilite ? hilite_keyword : "") << " LIMIT " << (settings.hilite ? hilite_none : "");
|
||||
limit_length->formatImpl(settings, state, frame);
|
||||
}
|
||||
}
|
||||
else if (clusters)
|
||||
{
|
||||
|
@ -46,6 +46,25 @@ bool ParserShowTablesQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expec
|
||||
if (s_databases.ignore(pos))
|
||||
{
|
||||
query->databases = true;
|
||||
|
||||
if (s_not.ignore(pos, expected))
|
||||
query->not_like = true;
|
||||
|
||||
if (bool insensitive = s_ilike.ignore(pos, expected); insensitive || s_like.ignore(pos, expected))
|
||||
{
|
||||
if (insensitive)
|
||||
query->case_insensitive_like = true;
|
||||
|
||||
if (!like_p.parse(pos, like, expected))
|
||||
return false;
|
||||
}
|
||||
else if (query->not_like)
|
||||
return false;
|
||||
if (s_limit.ignore(pos, expected))
|
||||
{
|
||||
if (!exp_elem.parse(pos, query->limit_length, expected))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (s_clusters.ignore(pos))
|
||||
{
|
||||
|
@ -0,0 +1 @@
|
||||
test_01470
|
3
tests/queries/0_stateless/01470_show_databases_like.sql
Normal file
3
tests/queries/0_stateless/01470_show_databases_like.sql
Normal file
@ -0,0 +1,3 @@
|
||||
create database if not exists test_01470;
|
||||
show databases like '%01470';
|
||||
drop database test_01470;
|
Loading…
Reference in New Issue
Block a user