TableFactor in sqlparser::ast - Rust

pub enum TableFactor {
Show 13 variants Table { name: ObjectName, alias: Option<TableAlias>, args: Option<TableFunctionArgs>, with_hints: Vec<Expr>, version: Option<TableVersion>, with_ordinality: bool, partitions: Vec<Ident>, json_path: Option<JsonPath>, sample: Option<TableSampleKind>, index_hints: Vec<TableIndexHints>, }, Derived { lateral: bool, subquery: Box<Query>, alias: Option<TableAlias>, sample: Option<TableSampleKind>, }, 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>, with_ordinality: bool, }, JsonTable { json_expr: Expr, json_path: Value, columns: Vec<JsonTableColumn>, alias: Option<TableAlias>, }, OpenJsonTable { json_expr: Expr, json_path: Option<Value>, columns: Vec<OpenJsonTableColumn>, alias: Option<TableAlias>, }, NestedJoin { table_with_joins: Box<TableWithJoins>, alias: Option<TableAlias>, }, Pivot { table: Box<TableFactor>, aggregate_functions: Vec<ExprWithAlias>, value_column: Vec<Expr>, value_source: PivotValueSource, default_on_null: Option<Expr>, alias: Option<TableAlias>, }, Unpivot { table: Box<TableFactor>, value: Expr, name: Ident, columns: Vec<ExprWithAlias>, null_inclusion: Option<NullInclusion>, 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>, }, XmlTable { namespaces: Vec<XmlNamespaceDefinition>, row_expression: Expr, passing: XmlPassingClause, columns: Vec<XmlTableColumn>, alias: Option<TableAlias>, }, SemanticView { name: ObjectName, dimensions: Vec<Expr>, metrics: Vec<Expr>, facts: Vec<Expr>, where_clause: Option<Expr>, alias: Option<TableAlias>, },
}
Expand description

A table name or a parenthesized subquery with an optional alias

§

A named table or relation, possibly with arguments, hints, or sampling.

Fields

Optional alias for the table (e.g. table AS t).

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.

MSSQL-specific WITH (...) hints such as NOLOCK.

Optional version qualifier to facilitate table time-travel, as supported by BigQuery and MSSQL.

For example, SELECT * FROM generate_series(1, 10) WITH ORDINALITY AS t(a, b); WITH ORDINALITY, supported by Postgres.

§

A derived table (a parenthesized subquery), optionally LATERAL.

Fields

Whether the derived table is LATERAL.

The subquery producing the derived table.

Optional alias for the derived table.

Optional table sample modifier

§

TABLE(<expr>)[ AS <alias> ]

Fields

Expression representing the table function call.

Optional alias for the table function result.

§

e.g. LATERAL FLATTEN(<args>)[ AS <alias> ]

Fields

Whether the function is LATERAL.

Name of the table function.

Arguments passed to the function.

Optional alias for the result of the function.

§
SELECT * FROM UNNEST ([10,20,30]) as numbers WITH OFFSET;
+---------+--------+
| numbers | offset |
+---------+--------+
| 10      | 0      |
| 20      | 1      |
| 30      | 2      |
+---------+--------+

Fields

Optional alias for the UNNEST table (e.g. UNNEST(...) AS t).

Expressions producing the arrays to be unnested.

Whether WITH OFFSET was specified to include element offsets.

Optional alias for the offset column when WITH OFFSET is used.

Whether WITH ORDINALITY was specified to include ordinality.

§

Fields

The JSON expression to be evaluated. It must evaluate to a json string

The 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.

§

Fields

The JSON expression to be evaluated. It must evaluate to a json string

The path to the array or object to be iterated over. It must evaluate to a json array or object.

§columns: Vec<OpenJsonTableColumn>

The columns to be extracted from each element of the array or object. Each column must have a name and a type.

§

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.

Fields

The nested join expression contained in parentheses.

Optional alias for the nested join.

§

Represents PIVOT operation on a table. For example FROM monthly_sales PIVOT(sum(amount) FOR MONTH IN ('JAN', 'FEB'))

BigQuery Snowflake

Fields

The input table to pivot.

Aggregate expressions used as pivot values (optionally aliased).

§value_column: Vec<Expr>

Columns producing the values to be pivoted.

Source of pivot values (e.g. list of literals or columns).

Optional expression providing a default when a pivot produces NULL.

Optional alias for the pivoted table.

§

Fields

The input table to unpivot.

Expression producing the unpivoted value.

Identifier used for the generated column name.

§columns: Vec<ExprWithAlias>

Columns or expressions to unpivot, optionally aliased.

Whether to include or exclude NULLs during unpivot.

Optional alias for the resulting table.

§

Fields

The input table to apply MATCH_RECOGNIZE on.

PARTITION BY <expr> [, ... ]

MEASURES <expr> [AS] <alias> [, ... ]

ONE ROW PER MATCH | ALL ROWS PER MATCH [ <option> ]

AFTER MATCH SKIP <option>

DEFINE <symbol> AS <expr> [, ... ]

§

The XMLTABLE table-valued function. Part of the SQL standard, supported by PostgreSQL, Oracle, and DB2.

https://www.postgresql.org/docs/15/functions-xml.html#FUNCTIONS-XML-PROCESSING

SELECT xmltable.*
FROM xmldata,
XMLTABLE('//ROWS/ROW'
    PASSING data
    COLUMNS id int PATH '@id',
    ordinality FOR ORDINALITY,
    "COUNTRY_NAME" text,
    country_id text PATH 'COUNTRY_ID',
    size_sq_km float PATH 'SIZE[@unit = "sq_km"]',
    size_other text PATH 'concat(SIZE[@unit!="sq_km"], " ", SIZE[@unit!="sq_km"]/@unit)',
    premier_name text PATH 'PREMIER_NAME' DEFAULT 'not specified'
);

Fields

Optional XMLNAMESPACES clause (empty if not present)

The row-generating XPath expression.

The PASSING clause specifying the document expression.

§

Fields

The name of the semantic model

List of dimensions or expression referring to dimensions (e.g. DATE_PART(‘year’, col))

List of metrics (references to objects like orders.value, value, orders.*)

List of facts or expressions referring to facts or dimensions.

WHERE clause for filtering

§
§
§
§
§
§