Enum sqlparser::ast::TableFactor
source · pub enum TableFactor {
Table {
name: ObjectName,
alias: Option<TableAlias>,
args: Option<Vec<FunctionArg>>,
with_hints: Vec<Expr>,
version: Option<TableVersion>,
partitions: Vec<Ident>,
},
Derived {
lateral: bool,
subquery: Box<Query>,
alias: Option<TableAlias>,
},
TableFunction {
expr: Expr,
alias: Option<TableAlias>,
},
Function {
lateral: bool,
name: ObjectName,
args: Vec<FunctionArg>,
alias: Option<TableAlias>,
},
UNNEST {
alias: Option<TableAlias>,
array_exprs: Vec<Expr>,
with_offset: bool,
with_offset_alias: Option<Ident>,
},
JsonTable {
json_expr: Expr,
json_path: Value,
columns: Vec<JsonTableColumn>,
alias: Option<TableAlias>,
},
NestedJoin {
table_with_joins: Box<TableWithJoins>,
alias: Option<TableAlias>,
},
Pivot {
table: Box<TableFactor>,
aggregate_functions: Vec<ExprWithAlias>,
value_column: Vec<Ident>,
value_source: PivotValueSource,
default_on_null: Option<Expr>,
alias: Option<TableAlias>,
},
Unpivot {
table: Box<TableFactor>,
value: Ident,
name: Ident,
columns: Vec<Ident>,
alias: Option<TableAlias>,
},
MatchRecognize {
table: Box<TableFactor>,
partition_by: Vec<Expr>,
order_by: Vec<OrderByExpr>,
measures: Vec<Measure>,
rows_per_match: Option<RowsPerMatch>,
after_match_skip: Option<AfterMatchSkip>,
pattern: MatchRecognizePattern,
symbols: Vec<SymbolDefinition>,
alias: Option<TableAlias>,
},
}Expand description
A table name or a parenthesized subquery with an optional alias
Variants§
Table
Fields
name: ObjectNamealias: Option<TableAlias>args: Option<Vec<FunctionArg>>Arguments of a table-valued function, as supported by Postgres
and MSSQL. Note that deprecated MSSQL FROM foo (NOLOCK) syntax
will also be parsed as args.
This field’s value is Some(v), where v is a (possibly empty)
vector of arguments, in the case of a table-valued function call,
whereas it’s None in the case of a regular table name.
version: Option<TableVersion>Optional version qualifier to facilitate table time-travel, as supported by BigQuery and MSSQL.
partitions: Vec<Ident>Partition selection, supported by MySQL.
Derived
TableFunction
TABLE(<expr>)[ AS <alias> ]
Function
e.g. LATERAL FLATTEN(<args>)[ AS <alias> ]
UNNEST
SELECT * FROM UNNEST ([10,20,30]) as numbers WITH OFFSET;
+---------+--------+
| numbers | offset |
+---------+--------+
| 10 | 0 |
| 20 | 1 |
| 30 | 2 |
+---------+--------+
Fields
alias: Option<TableAlias>JsonTable
The JSON_TABLE table-valued function.
Part of the SQL standard, but implemented only by MySQL, Oracle, and DB2.
https://modern-sql.com/blog/2017-06/whats-new-in-sql-2016#json_table https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html#function_json-table
SELECT * FROM JSON_TABLE(
'[{"a": 1, "b": 2}, {"a": 3, "b": 4}]',
'$[*]' COLUMNS(
a INT PATH '$.a' DEFAULT '0' ON EMPTY,
b INT PATH '$.b' NULL ON ERROR
)
) AS jt;
Fields
json_path: ValueThe path to the array or object to be iterated over. It must evaluate to a json array or object.
columns: Vec<JsonTableColumn>The columns to be extracted from each element of the array or object. Each column must have a name and a type.
alias: Option<TableAlias>The alias for the table.
NestedJoin
Represents a parenthesized table factor. The SQL spec only allows a
join expression ((foo <JOIN> bar [ <JOIN> baz ... ])) to be nested,
possibly several times.
The parser may also accept non-standard nesting of bare tables for some dialects, but the information about such nesting is stripped from AST.
Pivot
Represents PIVOT operation on a table.
For example FROM monthly_sales PIVOT(sum(amount) FOR MONTH IN ('JAN', 'FEB'))
Fields
table: Box<TableFactor>aggregate_functions: Vec<ExprWithAlias>value_source: PivotValueSourcealias: Option<TableAlias>Unpivot
An UNPIVOT operation on a table.
Syntax:
table UNPIVOT(value FOR name IN (column1, [ column2, ... ])) [ alias ]
See https://docs.snowflake.com/en/sql-reference/constructs/unpivot.
MatchRecognize
A MATCH_RECOGNIZE operation on a table.
See https://docs.snowflake.com/en/sql-reference/constructs/match_recognize.
Fields
table: Box<TableFactor>order_by: Vec<OrderByExpr>ORDER BY <expr> [, ... ]
rows_per_match: Option<RowsPerMatch>ONE ROW PER MATCH | ALL ROWS PER MATCH [ <option> ]
after_match_skip: Option<AfterMatchSkip>AFTER MATCH SKIP <option>
pattern: MatchRecognizePatternPATTERN ( <pattern> )
symbols: Vec<SymbolDefinition>DEFINE <symbol> AS <expr> [, ... ]
alias: Option<TableAlias>Trait Implementations§
source§impl Clone for TableFactor
impl Clone for TableFactor
source§fn clone(&self) -> TableFactor
fn clone(&self) -> TableFactor
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl Debug for TableFactor
impl Debug for TableFactor
source§impl<'de> Deserialize<'de> for TableFactor
impl<'de> Deserialize<'de> for TableFactor
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl Display for TableFactor
impl Display for TableFactor
source§impl Hash for TableFactor
impl Hash for TableFactor
source§impl Ord for TableFactor
impl Ord for TableFactor
source§fn cmp(&self, other: &TableFactor) -> Ordering
fn cmp(&self, other: &TableFactor) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl PartialEq for TableFactor
impl PartialEq for TableFactor
source§fn eq(&self, other: &TableFactor) -> bool
fn eq(&self, other: &TableFactor) -> bool
self and other values to be equal, and is used
by ==.source§impl PartialOrd for TableFactor
impl PartialOrd for TableFactor
source§fn partial_cmp(&self, other: &TableFactor) -> Option<Ordering>
fn partial_cmp(&self, other: &TableFactor) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read more