mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
add select all syntax
This commit is contained in:
parent
1e98917963
commit
7a04724b3c
@ -8,6 +8,7 @@
|
||||
#include <Parsers/parseIntervalKind.h>
|
||||
#include <Common/StringUtils/StringUtils.h>
|
||||
|
||||
#include <Parsers/CommonParsers.h>
|
||||
|
||||
namespace DB
|
||||
{
|
||||
@ -86,6 +87,9 @@ bool ParserList::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
|
||||
|
||||
auto parse_element = [&]
|
||||
{
|
||||
ParserKeyword all("ALL");
|
||||
all.ignore(pos, expected);
|
||||
|
||||
ASTPtr element;
|
||||
if (!elem_parser->parse(pos, element, expected))
|
||||
return false;
|
||||
|
@ -21,6 +21,7 @@ namespace ErrorCodes
|
||||
extern const int LIMIT_BY_WITH_TIES_IS_NOT_SUPPORTED;
|
||||
extern const int ROW_AND_ROWS_TOGETHER;
|
||||
extern const int FIRST_AND_NEXT_TOGETHER;
|
||||
extern const int LOGICAL_ERROR;
|
||||
}
|
||||
|
||||
|
||||
@ -30,6 +31,7 @@ bool ParserSelectQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
|
||||
node = select_query;
|
||||
|
||||
ParserKeyword s_select("SELECT");
|
||||
ParserKeyword s_all("ALL");
|
||||
ParserKeyword s_distinct("DISTINCT");
|
||||
ParserKeyword s_from("FROM");
|
||||
ParserKeyword s_prewhere("PREWHERE");
|
||||
@ -93,12 +95,22 @@ bool ParserSelectQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
|
||||
|
||||
/// SELECT [DISTINCT] [TOP N [WITH TIES]] expr list
|
||||
{
|
||||
bool has_all = false;
|
||||
if (!s_select.ignore(pos, expected))
|
||||
return false;
|
||||
|
||||
if (s_all.ignore(pos, expected))
|
||||
has_all = true;
|
||||
|
||||
if (s_distinct.ignore(pos, expected))
|
||||
select_query->distinct = true;
|
||||
|
||||
if (!has_all && s_all.ignore(pos, expected))
|
||||
has_all = true;
|
||||
|
||||
if (has_all && select_query->distinct)
|
||||
throw Exception("Can not use DISTINCT alongside ALL", ErrorCodes::LOGICAL_ERROR);
|
||||
|
||||
if (s_top.ignore(pos, expected))
|
||||
{
|
||||
ParserNumber num;
|
||||
|
@ -0,0 +1,7 @@
|
||||
a
|
||||
a
|
||||
1
|
||||
1
|
||||
2
|
||||
45
|
||||
45
|
9
tests/queries/0_stateless/01632_select_all_syntax.sql
Normal file
9
tests/queries/0_stateless/01632_select_all_syntax.sql
Normal file
@ -0,0 +1,9 @@
|
||||
SELECT ALL 'a';
|
||||
SELECT DISTINCT 'a';
|
||||
SELECT ALL * FROM (SELECT 1 UNION ALL SELECT 1);
|
||||
SELECT DISTINCT * FROM (SELECT 2 UNION ALL SELECT 2);
|
||||
SELECT ALL DISTINCT 1; -- { clientError 49 }
|
||||
SELECT DISTINCT ALL 1; -- { clientError 49 }
|
||||
|
||||
SELECT sum(number) FROM numbers(10);
|
||||
SELECT sum(ALL number) FROM numbers(10);
|
Loading…
Reference in New Issue
Block a user