SELECT Overview
Contents
SELECT Overview#
Syntax#
SelectStmt#
SelectStmt
::= WithClause ( NoTableSelectClause | SelectStmtFromTable)
WithClause
::= 'WITH' non_recursive_cte [, ...]
non_recursive_cte
::= cte_name 'AS' '(' SelectStmt ')'
NoTableSelectClause
::= 'SELECT' SelectExprList
SelectStmtFromTable
::= SelectStmtBasic 'FROM' TableRefs [WhereClause] [GroupByClause] [HavingClause] [WindowClause] [OrderByClause] [LimitClause]
JoinClause
::= TableRef JoinType 'JOIN' TableRef [OrderClause] 'ON' Expression
JoinType ::= 'LAST'
WhereClause
::= 'WHERE' Expression
GroupByClause
::= 'GROUP' 'BY' ByList
HavingClause
::= 'HAVING' Expression
WindowClause
::= ( 'WINDOW' WindowDefinition ( ',' WindowDefinition )* )
OrderByClause ::= 'ORDER' 'BY' ByList
ByList ::= ByItem ( ',' ByItem )*
ByItem ::= Expression Order
Order ::= ( 'ASC' | 'DESC' )?
WindowClauseOptional
::= ( 'WINDOW' WindowDefinition ( ',' WindowDefinition )* )?
WindowDefinition
::= WindowName 'AS' WindowSpec
WindowSpec
::= '(' WindowSpecDetails ')'
WindowSpecDetails
::= [ExistingWindowName] [WindowUnionClause] WindowPartitionClause WindowOrderByClause WindowFrameClause (WindowAttribute)*
WindowUnionClause
:: = ( 'UNION' TableRefs)
WindowPartitionClause
::= ( 'PARTITION' 'BY' ByList )
WindowOrderByClause
::= ( 'ORDER' 'BY' ByList )
WindowFrameClause
::= ( WindowFrameUnits WindowFrameBounds [WindowFrameMaxSize] )
WindowFrameUnits
::= 'ROWS'
| 'ROWS_RANGE'
WindowFrameBounds
::= 'BETWEEN' WindowFrameBound 'AND' WindowFrameBound
WindowFrameBound
::= ( 'UNBOUNDED' | NumLiteral | IntervalLiteral ) ['OPEN'] 'PRECEDING'
| 'CURRENT' 'ROW'
WindowAttribute
::= WindowExcludeCurrentTime
| WindowExcludeCurrentRow
| WindowInstanceNotInWindow
WindowExcludeCurrentTime
::= 'EXCLUDE' 'CURRENT_TIME'
WindowExcludeCurrentRow
::= 'EXCLUDE' 'CURRENT_ROW'
WindowInstanceNotInWindow
:: = 'INSTANCE_NOT_IN_WINDOW'
WindowFrameMaxSize
:: = 'MAXSIZE' NumLiteral
SelectExprList#
SelectExprList
::= SelectExpr ( ',' SelectExpr )*
SelectExpr ::= ( Identifier '.' ( Identifier '.' )? )? '*'
| ( Expression | '{' Identifier Expression '}' ) ['AS' Identifier]
TableRefs#
TableRefs
::= EscapedTableRef ( ',' EscapedTableRef )*
TableRef ::= TableFactor
| JoinClause
TableFactor
::= TableName [TableAsName]
| '(' ( ( SelectStmt ) ')' TableAsName | TableRefs ')' )
TableAsName
::= 'AS'? Identifier
SELECT Statement#
|
Offline Mode |
Online Preview Mode |
Online Request Mode |
Note |
---|---|---|---|---|
|
|
|
A list of projection operations, generally including column names, expressions, or ‘*’ for all columns. |
|
|
|
|
The FROM clause indicates the data source. |
|
|
|
|
The JOIN clause indicates that the data source comes from multiple joined tables. OpenMLDB currently only supports LAST JOIN. For Online Request Mode, please follow the specification of LAST JOIN under Online Request Mode |
|
|
The WHERE clause is used to set filter conditions, and only the data that meets the conditions will be included in the query result. |
|||
|
|
The GROUP BY clause is used to group the query results.The grouping conditions only support simple columns. |
||
|
|
The HAVING clause is similar to the WHERE clause. The HAVING clause filters data after GROUP BY, and the WHERE clause is used to filter records before aggregation. |
||
|
|
|
The WINDOW clause is used to define one or several windows. Windows can be named or anonymous. Users can call aggregate functions on the window to perform analysis ( |
|
|
|
The LIMIT clause is used to limit the number of results. OpenMLDB currently only supports one parameter to limit the maximum number of rows of returned data. |
||
|
Standard SQL also supports the ORDER BY keyword, however OpenMLDB does not support this keyword currently. For example, the query |
Warning
The SELECT
running in online mode or the stand-alone version may not obtain complete data.
The largest number of bytes to scan is limited, namely scan_max_bytes_size
, default value is unlimited. But if you set the value of scan_max_bytes_size
to a specific value, the SELECT
statement will only scan the data within the specified size. If the select results are truncated, the message of reach the max byte ...
will be recorded in the tablet’s log, but there will be no error.
Even if the scan_max_bytes_size
is set to unlimited, the SELECT
statement may failed, e.g. client errors body_size=xxx from xx:xxxx is too large
, Fail to parse response from xx:xxxx by baidu_std at client-side
. We don’t recommend to use SELECT
in online mode or the stand-alone version. If you want to get the count of the online table, please use SELECT COUNT(*) FROM table_name;
.