Expression Nodes¶
Expression nodes represent computational elements in SQL statements, including mathematical operations, logical conditions, function calls, and value comparisons. They form the building blocks of SQL logic.
Overview¶
Expression nodes inherit from TExpression
and represent any SQL element that evaluates to a value. They can be simple literals, column references, or complex nested expressions involving multiple operations.
Expression Categories¶
Basic Elements¶
- Basic Expressions -
TExpression
- Core expression concepts
- Expression types and structure
-
Navigation and traversal patterns
-
Column References -
TObjectName
- Table and column identifiers
- Qualified and unqualified names
- Alias handling
Operations and Functions¶
- Arithmetic Expressions
- Mathematical operations (+, -, *, /, %)
- Operator precedence
-
Numeric type handling
- Boolean operations (AND, OR, NOT)
- Comparison operators (=, <>, <, >, <=, >=)
-
Pattern matching (LIKE, REGEXP)
-
Function Calls -
TFunctionCall
- Built-in SQL functions
- User-defined functions
- Aggregate functions
- Window functions
Conditional Logic¶
- CASE Expressions -
TCaseExpression
- Simple and searched CASE
- Conditional value selection
-
NULL handling patterns
- Scalar subqueries
- EXISTS conditions
- IN/NOT IN with subqueries
Advanced Constructs¶
- Window Expressions
- OVER clauses
- Partitioning and ordering
-
Frame specifications
- Array access operations
- JSON path expressions
- Database-specific syntax
Expression Types¶
The TExpression
class uses EExpressionType
to distinguish between different expression types:
Type | Description | Example |
---|---|---|
simple_object_name_t |
Column/table reference | users.id |
function_t |
Function call | COUNT(*) |
arithmetic_plus_t |
Addition | a + b |
arithmetic_minus_t |
Subtraction | a - b |
logical_and_t |
AND operation | a AND b |
logical_or_t |
OR operation | a OR b |
comparison_eq_t |
Equality | a = b |
comparison_ne_t |
Inequality | a <> b |
parenthesis_t |
Parenthesized | (expression) |
case_t |
CASE expression | CASE WHEN ... END |
Common Usage Patterns¶
Expression Type Identification¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
Expression Tree Traversal¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
Finding Column References¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
Expression Context¶
Expressions appear in various SQL contexts:
- SELECT lists: Column values and calculations
- WHERE clauses: Filter conditions
- JOIN conditions: Table relationship criteria
- GROUP BY: Grouping specifications
- ORDER BY: Sort criteria
- HAVING: Aggregate filter conditions
- CASE statements: Conditional logic
Database-Specific Features¶
SQL Server¶
IIF()
function for inline conditionalsCHOOSE()
function for indexed selectionTRY_CAST()
andTRY_CONVERT()
functions
PostgreSQL¶
- Array operations and indexing
- JSON/JSONB path operators
- Regular expression operators (
~
,~*
)
Oracle¶
DECODE()
function- Hierarchical query operators (
PRIOR
,CONNECT_BY_ROOT
) - Advanced analytic functions
MySQL¶
IF()
function- Regular expression functions (
REGEXP
,RLIKE
) - JSON functions and operators
See Also¶
- SQL Clauses - Expressions within clauses
- Function Calls - Detailed function documentation
- Basic Parsing Tutorial - Getting started
- API Documentation - Method-level reference