Skip to main content

TableFactor

Enum TableFactor 

Source
pub enum TableFactor<X: Extension = NoExt> {
Show 16 variants Table { name: ObjectName, inheritance: RelationInheritance, json_path: ThinVec<SemiStructuredPathSegment<X>>, version: Option<Box<TableVersion<X>>>, partition: ThinVec<Ident>, alias: Option<Box<TableAlias>>, indexed_by: Option<Box<IndexedBy>>, index_hints: ThinVec<IndexHint>, sample: Option<TableSample<X>>, table_hints: ThinVec<TableHint>, meta: Meta, }, Derived { lateral: bool, subquery: Box<Query<X>>, alias: Option<Box<TableAlias>>, spelling: DerivedSpelling, meta: Meta, }, Function { lateral: bool, function: Box<FunctionCall<X>>, with_ordinality: bool, alias: Option<Box<TableAlias>>, column_defs: ThinVec<TableFunctionColumn<X>>, meta: Meta, }, RowsFrom { lateral: bool, functions: ThinVec<RowsFromItem<X>>, with_ordinality: bool, alias: Option<Box<TableAlias>>, meta: Meta, }, Unnest { lateral: bool, array_exprs: ThinVec<Expr<X>>, with_ordinality: bool, alias: Option<Box<TableAlias>>, column_defs: ThinVec<TableFunctionColumn<X>>, with_offset: bool, with_offset_alias: Option<Ident>, meta: Meta, }, NestedJoin { table: Box<TableWithJoins<X>>, alias: Option<Box<TableAlias>>, meta: Meta, }, SpecialFunction { keyword: SpecialFunctionKeyword, precision: Option<u32>, alias: Option<Box<TableAlias>>, meta: Meta, }, Pivot { pivot: Box<Pivot<X>>, alias: Option<Box<TableAlias>>, meta: Meta, }, Unpivot { unpivot: Box<Unpivot<X>>, alias: Option<Box<TableAlias>>, meta: Meta, }, MatchRecognize { match_recognize: Box<MatchRecognize<X>>, alias: Option<Box<TableAlias>>, meta: Meta, }, ShowRef { show: Box<ShowRef<X>>, alias: Option<Box<TableAlias>>, meta: Meta, }, JsonTable { json_table: Box<JsonTable<X>>, alias: Option<Box<TableAlias>>, meta: Meta, }, XmlTable { xml_table: Box<XmlTable<X>>, alias: Option<Box<TableAlias>>, meta: Meta, }, OpenJson { open_json: Box<OpenJson<X>>, alias: Option<Box<TableAlias>>, meta: Meta, }, TableExpr { expr: Box<Expr<X>>, alias: Option<Box<TableAlias>>, meta: Meta, }, Other { ext: X, meta: Meta, },
}
Expand description

The SQL table factor forms represented by the AST.

Variants§

§

Table

A named table/relation reference, with optional alias, hints, sampling, and time-travel.

Fields

§name: ObjectName

The table name (one or more dot-separated parts).

§inheritance: RelationInheritance

PostgreSQL ONLY/* inheritance modifier; see RelationInheritance.

§json_path: ThinVec<SemiStructuredPathSegment<X>>

A PartiQL / SUPER JSON path navigating into a semi-structured column at the table-source position (FROM src[0].a), attached directly to the table name. Redshift’s SUPER navigation and Snowflake’s PartiQL access (sqlparser-rs’s TableFactor::Table::json_path, gated by its supports_partiql). The path is entered only by a [ immediately after the name — a bracket index root, then .key / [index] suffixes — so a dotted FROM src.a.b stays a compound name, never a path. Empty when absent (the path is always non-empty when present, so an empty ThinVec is the unambiguous “no path” sentinel — the same pattern as partition). Reuses the expression-position SemiStructuredPathSegment vocabulary. Gated by TableExpressionSyntax::table_json_path.

§version: Option<Box<TableVersion<X>>>

A version / time-travel modifier (FOR SYSTEM_TIME AS OF …, VERSION AS OF …), written between the table name and the alias; None when absent. Boxed to keep this hot enum within its size budget (ADR-0007). Gated by TableExpressionSyntax::table_version; see TableVersion.

§partition: ThinVec<Ident>

MySQL explicit partition selection PARTITION (p0, p1), written between the table name and the alias; empty when absent. Restricts the scan to the named partitions/subpartitions. Gated by TableExpressionSyntax::partition_selection.

§alias: Option<Box<TableAlias>>

Alias assigned by this syntax.

§indexed_by: Option<Box<IndexedBy>>

SQLite INDEXED BY <index> / NOT INDEXED index directive, written after the table name and its optional alias (FROM t AS e INDEXED BY ix); None when absent. Boxed to keep this hot enum within its size budget (ADR-0007). A separate axis from MySQL index_hints: a different dialect, grammar, and cardinality (see IndexedBy). Gated by TableExpressionSyntax::indexed_by.

§index_hints: ThinVec<IndexHint>

MySQL index hints (USE|FORCE|IGNORE INDEX|KEY …), written after the alias; empty when absent. A list because MySQL admits several comma-joined hints on one table. Gated by TableExpressionSyntax::index_hints.

§sample: Option<TableSample<X>>

Optional sample for this syntax.

§table_hints: ThinVec<TableHint>

MSSQL / T-SQL WITH (...) table hints (WITH (NOLOCK), WITH (INDEX(ix), FORCESEEK)), written after the alias and the tablesample clause; empty when absent. A list because T-SQL admits several comma-joined hints in one WITH (...). A separate axis from index_hints: a different dialect (T-SQL vs MySQL) and a different grammar position. Gated by TableExpressionSyntax::table_hints.

§meta: Meta

Source location and node identity.

§

Derived

A derived table — a parenthesized subquery in FROM, optionally LATERAL.

Fields

§lateral: bool

Whether the lateral form was present in the source.

§subquery: Box<Query<X>>

The subquery producing the derived rows.

§alias: Option<Box<TableAlias>>

Alias assigned by this syntax.

§spelling: DerivedSpelling

Whether the source wrote the standard parenthesized ( <query> ) or DuckDB’s bare FROM VALUES (…) AS t row list (no parentheses); see DerivedSpelling. A BareValues factor’s subquery body is always a SetExpr::Values and its alias is always Some (the parser rejects a bare FROM VALUES without one), the invariant the Render impl relies on to drop the parentheses.

§meta: Meta

Source location and node identity.

§

Function

A set-returning function used as a table (a table function), optionally LATERAL.

Fields

§lateral: bool

Whether the lateral form was present in the source.

§function: Box<FunctionCall<X>>

The table-function call; see FunctionCall.

§with_ordinality: bool

Whether the with ordinality form was present in the source.

§alias: Option<Box<TableAlias>>

Alias assigned by this syntax.

§column_defs: ThinVec<TableFunctionColumn<X>>

PostgreSQL func_alias_clause column definition list, e.g. the (id int, name text) of func(...) AS x(id int, name text). Empty unless the function returns an anonymous record typed at the call site.

§meta: Meta

Source location and node identity.

§

RowsFrom

A PostgreSQL ROWS FROM(f1(…), f2(…)) multi-function table factor.

Fields

§lateral: bool

Whether the lateral form was present in the source.

§functions: ThinVec<RowsFromItem<X>>

functions in source order.

§with_ordinality: bool

Whether the with ordinality form was present in the source.

§alias: Option<Box<TableAlias>>

Alias assigned by this syntax.

§meta: Meta

Source location and node identity.

§

Unnest

A first-class UNNEST(<expr>[, <expr>…]) table factor: an array/collection expression expanded into a relation. Modelled as a dedicated node rather than the generic Function table function for planner-consumer parity (the downstream planner keys on a distinct UNNEST) — even though PostgreSQL itself lowers FROM unnest(…) to the same RangeFunction as any other set-returning function (its parse tree draws no distinction). Gated by TableFactorSyntax::unnest; reached only when UNNEST is immediately followed by (, so a bare UNNEST stays an ordinary relation name.

Fields

§lateral: bool

LATERAL UNNEST(…): the array expressions correlate against earlier FROM items (PostgreSQL CROSS JOIN LATERAL unnest(t.arr)).

§array_exprs: ThinVec<Expr<X>>

The unnested array expressions. PostgreSQL admits several (unnest(a, b), the multi-array zip); DuckDB and BigQuery take exactly one. An empty list models PostgreSQL’s degenerate unnest() accept.

§with_ordinality: bool

PostgreSQL/DuckDB WITH ORDINALITY: append a 1-based ordinal column. BigQuery has no WITH ORDINALITY — it spells the same idea WITH OFFSET (0-based).

§alias: Option<Box<TableAlias>>

The correlation alias and its optional untyped column-name list (AS u(v, ord)), read before the with_offset tail so both the PostgreSQL (… WITH ORDINALITY AS u(…)) and BigQuery (… AS u WITH OFFSET) orderings round-trip.

§column_defs: ThinVec<TableFunctionColumn<X>>

PostgreSQL’s typed func_alias_clause column-definition list (unnest(x) AS t(a int)); empty for the common untyped form. Carried so the rare typed spelling round-trips losslessly rather than over-rejecting.

§with_offset: bool

BigQuery WITH OFFSET: append a 0-based offset column. Gated by TableFactorSyntax::unnest_with_offset — a preset-less flag (no shipped dialect enables it, mirroring QueryTailSyntax::pipe_syntax), since only BigQuery/ZetaSQL accepts the tail and there is no BigQuery oracle yet.

§with_offset_alias: Option<Ident>

The BigQuery WITH OFFSET AS <alias> column alias; None for a bare WITH OFFSET, and always None when with_offset is false.

§meta: Meta

Source location and node identity.

§

NestedJoin

A parenthesized join nested as a table factor: (t1 JOIN t2 ON …).

Fields

§table: Box<TableWithJoins<X>>

The parenthesized join tree; see TableWithJoins.

§alias: Option<Box<TableAlias>>

Alias assigned by this syntax.

§meta: Meta

Source location and node identity.

§

SpecialFunction

A bare SQL special value function used as a table reference (PostgreSQL func_table: func_expr_windowless, e.g. SELECT * FROM current_date): pg_query lowers this to a RangeFunction wrapping a SQLValueFunction, distinct from an ordinary call — mirrors Expr::SpecialFunction, the same grammar production in expression position.

Fields

§keyword: SpecialFunctionKeyword

Which special-value function; see SpecialFunctionKeyword.

§precision: Option<u32>

The (precision) modifier, only valid on the temporal forms (mirrors Expr::SpecialFunction’s precision).

§alias: Option<Box<TableAlias>>

Alias assigned by this syntax.

§meta: Meta

Source location and node identity.

§

Pivot

DuckDB’s <source> PIVOT (<aggregates> FOR <col> IN (<values>) [GROUP BY …]) table factor. The Pivot core is shared with the leading-keyword Statement::Pivot (tagged PivotSpelling::TableFactor); this position owns the trailing AS p alias the statement form has no place for. Boxed — like the other payload-bearing variants — to keep this hot enum within its size budget. Gated by TableFactorSyntax::pivot.

Fields

§pivot: Box<Pivot<X>>

The pivot operation; see Pivot.

§alias: Option<Box<TableAlias>>

Alias assigned by this syntax.

§meta: Meta

Source location and node identity.

§

Unpivot

DuckDB’s <source> UNPIVOT [… NULLS] (<value> FOR <name> IN (<cols>)) table factor — the Unpivot counterpart of Pivot, sharing its core with Statement::Unpivot. Gated by TableFactorSyntax::unpivot.

Fields

§unpivot: Box<Unpivot<X>>

The unpivot operation; see Unpivot.

§alias: Option<Box<TableAlias>>

Alias assigned by this syntax.

§meta: Meta

Source location and node identity.

§

MatchRecognize

The SQL:2016 <source> MATCH_RECOGNIZE (…) row-pattern-recognition table factor (Snowflake / Oracle). The MatchRecognize operator core carries the PARTITION BY / ORDER BY / MEASURES / rows-per-match / after-match-skip / PATTERN / SUBSET / DEFINE clauses; this position owns the trailing AS mr alias. Boxed — like the other payload-bearing variants — to keep this hot enum within its size budget (ADR-0007). Gated by TableFactorSyntax::match_recognize.

Fields

§match_recognize: Box<MatchRecognize<X>>

The MATCH_RECOGNIZE operator; see MatchRecognize.

§alias: Option<Box<TableAlias>>

Alias assigned by this syntax.

§meta: Meta

Source location and node identity.

§

ShowRef

DuckDB’s DESCRIBE/SHOW/SUMMARIZE utility standing as a table source — DuckDB’s SHOW_REF table reference (FROM (DESCRIBE SELECT …), FROM (DESCRIBE PIVOT …), FROM (SHOW databases); all probed on 1.5.4). Unlike Pivot/Unpivot, these are relation-producing constructs, not query bodies — DuckDB parse-rejects them at CTE-body position (A CTE needs a SELECT) while admitting them here — so they get a table-factor wrapper around the shared ShowRef core, the shape DuckDB itself uses (its SHOW_REF node carries the same kind + target). This position owns the trailing AS t alias. Boxed to keep this hot enum within its size budget. Gated by TableFactorSyntax::show_ref.

Fields

§show: Box<ShowRef<X>>

The DESCRIBE/SHOW/SUMMARIZE reference; see ShowRef.

§alias: Option<Box<TableAlias>>

Alias assigned by this syntax.

§meta: Meta

Source location and node identity.

§

JsonTable

SQL/JSON JSON_TABLE(…) table factor (SQL:2016) — a JSON document decomposed into a relation by a COLUMNS specification. Boxed to keep this hot enum within its size budget. Gated by TableFactorSyntax::json_table.

Fields

§json_table: Box<JsonTable<X>>

The JSON_TABLE(...) specification; see JsonTable.

§alias: Option<Box<TableAlias>>

Alias assigned by this syntax.

§meta: Meta

Source location and node identity.

§

XmlTable

SQL/XML XMLTABLE(…) table factor (SQL:2006) — an XML document decomposed into a relation by an XPath row expression and per-column paths. Boxed to keep this hot enum within its size budget. Gated by TableFactorSyntax::xml_table.

Fields

§xml_table: Box<XmlTable<X>>

The XMLTABLE(...) specification; see XmlTable.

§alias: Option<Box<TableAlias>>

Alias assigned by this syntax.

§meta: Meta

Source location and node identity.

§

OpenJson

SQL Server’s OPENJSON(<json> [, <path>]) [WITH (<col> <type> [<path>] [AS JSON], …)] table factor — a JSON document parsed into a relation, either with the default key/value/type schema (no WITH) or an explicit column schema. Boxed to keep this hot enum within its size budget (ADR-0007). Gated by TableFactorSyntax::open_json.

Fields

§open_json: Box<OpenJson<X>>

The OPENJSON(...) specification; see OpenJson.

§alias: Option<Box<TableAlias>>

Alias assigned by this syntax.

§meta: Meta

Source location and node identity.

§

TableExpr

TABLE(<expr>) — an arbitrary expression evaluated as a set-returning table source (sqlparser-rs’s TableFactor::TableFunction). Distinct from a named table function (Function, FROM f(1)), whose head is a call, not a parenthesized expression, and from the standalone TABLE t query form (Select::spelling SelectSpelling::TableCommand), which is a statement-level <explicit table>, not a FROM-position factor at all. Only Snowflake and Oracle document this exact shape and neither carries a differential oracle here, so this is gated TableFactorSyntax::table_expr_factor, on for Lenient only. Boxed to keep this hot enum within its size budget.

Fields

§expr: Box<Expr<X>>

Expression evaluated by this syntax.

§alias: Option<Box<TableAlias>>

Alias assigned by this syntax.

§meta: Meta

Source location and node identity.

§

Other

Dialect extension node supplied by the extension type.

Fields

§ext: X

The dialect extension node value.

§meta: Meta

Source location and node identity.

Implementations§

Source§

impl<X: Extension> TableFactor<X>

Source

pub fn alias_slot_mut(&mut self) -> Option<&mut Option<Box<TableAlias>>>

A mutable handle to this factor’s correlation-alias slot, or None for the extension Other variant, which carries no alias.

Every grammar factor holds an Option<Box<TableAlias>>; exposing it uniformly lets a caller inspect or set the alias without matching all twelve variants — used by the DuckDB prefix-colon-alias reader (FROM <alias> : <factor>) to attach the alias it parsed ahead of the factor.

Trait Implementations§

Source§

impl<X: Clone + Extension> Clone for TableFactor<X>

Source§

fn clone(&self) -> TableFactor<X>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<X: Debug + Extension> Debug for TableFactor<X>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de, X> Deserialize<'de> for TableFactor<X>
where X: Deserialize<'de> + Extension,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<X: Eq + Extension> Eq for TableFactor<X>

Source§

impl<X: Hash + Extension> Hash for TableFactor<X>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<X: PartialEq + Extension> PartialEq for TableFactor<X>

Source§

fn eq(&self, other: &TableFactor<X>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<X: Extension + Render> Render for TableFactor<X>

Source§

fn render(&self, ctx: &RenderCtx<'_>, f: &mut Formatter<'_>) -> Result

Return the render for this value.
Source§

fn operand_binding_power(&self) -> Option<BindingPower>

The binding power this node contributes when it appears as an operand, or None (the default) for a self-delimiting node — an atom, call, or constructor — that never needs parentheses. Read more
Source§

impl<X> Serialize for TableFactor<X>
where X: Serialize + Extension,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<X: Extension> Spanned for TableFactor<X>

Source§

fn span(&self) -> Span

Return the span for this value.
Source§

impl<X: PartialEq + Extension> StructuralPartialEq for TableFactor<X>

Auto Trait Implementations§

§

impl<X> Freeze for TableFactor<X>
where X: Freeze,

§

impl<X> RefUnwindSafe for TableFactor<X>
where X: RefUnwindSafe,

§

impl<X> Send for TableFactor<X>
where X: Send,

§

impl<X> Sync for TableFactor<X>
where X: Sync,

§

impl<X> Unpin for TableFactor<X>
where X: Unpin,

§

impl<X> UnsafeUnpin for TableFactor<X>
where X: UnsafeUnpin,

§

impl<X> UnwindSafe for TableFactor<X>
where X: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DynAstExt for T
where T: Extension + Render + 'static,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Erase to &dyn Any for downcasting a node back to its concrete type.
Source§

fn dyn_clone(&self) -> Box<dyn DynAstExt>

Clone into a fresh box — the object-safe stand-in for Clone (whose Self-returning signature cannot go through a vtable).
Source§

fn dyn_eq(&self, other: &dyn DynAstExt) -> bool

Structural equality against another erased node — the object-safe stand-in for PartialEq (whose &Self argument cannot go through a vtable). Equal iff other holds the same concrete type and that type deems the values equal; differently-typed nodes are never equal.
Source§

fn dyn_hash(&self, state: &mut dyn Hasher)

Feed this node’s hash into an erased hasher — the object-safe stand-in for Hash::hash (whose generic H: Hasher cannot go through a vtable).
Source§

impl<T> Extension for T
where T: Clone + Debug + Eq + Hash + Spanned,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> RenderExt for T
where T: Render,

Source§

fn displayed<'a>(&'a self, ctx: &'a RenderCtx<'a>) -> Displayed<'a, T>

Pair this node with an explicit canonical RenderCtx so format!, to_string, and {} render it. This is the canonical path: the ctx’s resolver and source must match the node’s parse.
Source§

fn debug_sql<'a>(&'a self, resolver: &'a dyn Resolver) -> DebugSql<'a, Self>
where Self: Sized,

Render this node for debugging against an explicitly-supplied resolver (the debug-SQL mitigation), returning a Display adapter. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.