Skip to content

Commit 1163b16

Browse files
Update expression-syntax.md (pingcap#3288)
* Update expression-syntax.md * Update expression-syntax.md delete spaces * Update expression-syntax.md * Apply suggestions from code review Co-authored-by: Keke Yi <[email protected]> Co-authored-by: Keke Yi <[email protected]>
1 parent f7f2075 commit 1163b16

File tree

1 file changed

+29
-60
lines changed

1 file changed

+29
-60
lines changed

expression-syntax.md

+29-60
Original file line numberDiff line numberDiff line change
@@ -6,63 +6,32 @@ aliases: ['/docs/dev/expression-syntax/','/docs/dev/reference/sql/language-struc
66

77
# Expression Syntax
88

9-
The following rules define the expression syntax in TiDB. You can find the definition in `parser/parser.y`. The syntax parsing in TiDB is based on Yacc.
10-
11-
```
12-
Expression:
13-
singleAtIdentifier assignmentEq Expression
14-
| Expression logOr Expression
15-
| Expression "XOR" Expression
16-
| Expression logAnd Expression
17-
| "NOT" Expression
18-
| Factor IsOrNotOp trueKwd
19-
| Factor IsOrNotOp falseKwd
20-
| Factor IsOrNotOp "UNKNOWN"
21-
| Factor
22-
23-
Factor:
24-
Factor IsOrNotOp "NULL"
25-
| Factor CompareOp PredicateExpr
26-
| Factor CompareOp singleAtIdentifier assignmentEq PredicateExpr
27-
| Factor CompareOp AnyOrAll SubSelect
28-
| PredicateExpr
29-
30-
PredicateExpr:
31-
PrimaryFactor InOrNotOp '(' ExpressionList ')'
32-
| PrimaryFactor InOrNotOp SubSelect
33-
| PrimaryFactor BetweenOrNotOp PrimaryFactor "AND" PredicateExpr
34-
| PrimaryFactor LikeOrNotOp PrimaryExpression LikeEscapeOpt
35-
| PrimaryFactor RegexpOrNotOp PrimaryExpression
36-
| PrimaryFactor
37-
38-
PrimaryFactor:
39-
PrimaryFactor '|' PrimaryFactor
40-
| PrimaryFactor '&' PrimaryFactor
41-
| PrimaryFactor "<<" PrimaryFactor
42-
| PrimaryFactor ">>" PrimaryFactor
43-
| PrimaryFactor '+' PrimaryFactor
44-
| PrimaryFactor '-' PrimaryFactor
45-
| PrimaryFactor '*' PrimaryFactor
46-
| PrimaryFactor '/' PrimaryFactor
47-
| PrimaryFactor '%' PrimaryFactor
48-
| PrimaryFactor "DIV" PrimaryFactor
49-
| PrimaryFactor "MOD" PrimaryFactor
50-
| PrimaryFactor '^' PrimaryFactor
51-
| PrimaryExpression
52-
53-
PrimaryExpression:
54-
Operand
55-
| FunctionCallKeyword
56-
| FunctionCallNonKeyword
57-
| FunctionCallAgg
58-
| FunctionCallGeneric
59-
| Identifier jss stringLit
60-
| Identifier juss stringLit
61-
| SubSelect
62-
| '!' PrimaryExpression
63-
| '~' PrimaryExpression
64-
| '-' PrimaryExpression
65-
| '+' PrimaryExpression
66-
| "BINARY" PrimaryExpression
67-
| PrimaryExpression "COLLATE" StringName
68-
```
9+
An expression is a combination of one or more values, operators, or functions. In TiDB, expressions are mainly used in various clauses of the `SELECT` statement, including Group by clause, Where clause, Having clause, Join condition and window function. In addition, some DDL statements also use expressions, such as the setting of the default values, columns, and partition rules when creating tables.
10+
11+
The expressions can be divided into the following types:
12+
13+
- Identifier. For reference, see [Schema object names](/schema-object-names.md).
14+
15+
- Predicates, numeric values, strings, date expressions. The [Literal values](/literal-values.md) of these types are also expressions.
16+
17+
- Function calls and window functions. For reference, see [Functions and operators overview](/functions-and-operators/functions-and-operators-overview.md) and [Window functions](/functions-and-operators/window-functions.md)
18+
19+
- ParamMarker (`?`), system variables, user variables and CASE expressions.
20+
21+
The following rules are the expression syntax, which is based on the [parser.y](https://github.com/pingcap/parser/blob/master/parser.y) rules of TiDB parser. For the navigable version of the following syntax diagram, refer to [TiDB SQL Syntax Diagram](https://pingcap.github.io/sqlgram/#Expression).
22+
23+
**Expression:**
24+
25+
![Expression](/media/sqlgram/Expression.png)
26+
27+
**PredicateExpr:**
28+
29+
![PredicateExpr](/media/sqlgram/PredicateExpr.png)
30+
31+
**BitExpr:**
32+
33+
![BitExpr](/media/sqlgram/BitExpr.png)
34+
35+
**SimpleExpr:**
36+
37+
![SimpleExpr](/media/sqlgram/SimpleExpr.png)

0 commit comments

Comments
 (0)