classCommonTableFacts
final class CommonTableFacts
Binds the common table expressions of a WITH clause.
Rule: PG-COMMON-TABLE-001. Without RECURSIVE a common table is visible to the common tables after it and to the statement; with RECURSIVE it is visible to every common table of the clause, which are derived after the tables they refer to, and to itself. A table that refers to itself must be a UNION of a non-recursive and a recursive part (PG-SET-OPERATION-001 binds the recursive part); two tables that refer to each other are reported. The columns of a table are the output columns of its statement, renamed by its column list; more names than columns are reported. SEARCH adds its sequence column (a record, an array of records for depth-first) and CYCLE its mark column (boolean, or the common type of the TO and DEFAULT values, which see no column) and path column (an array of records); their columns must be columns of the table, and both require a recursive table. A repeated name is reported, and so is MERGE as the statement of a common table before release 17. The bindings join the environment of the holder at its own query level. Terminates: each table is derived once. Source: https://www.postgresql.org/docs/17/queries-with.html. Status: Implemented.
Methods§
public function bind(WithClause $with, Derivation $derivation, Environment $outer): EnvironmentDerives the tables and answers the environment in which they are visible.
Parameters
$with | WithClause | |
$derivation | Derivation | |
$outer | Environment |
Returns
Called from 1
Calls 15
- method-call Derivation::report() line 72
- new QueryMisuse line 72
- class-const QueryMisuseRule::DuplicateCommonTable() line 72
- method-call CommonTableFacts::uses() line 75
- method-call CommonTableFacts::order() line 78
- new CommonBinding line 81
- new RowShape line 81
- method-call CommonTableFacts::recursiveForm() line 82
- class-const QueryMisuseRule::RecursiveForm() line 83
- class-const GrammarRelease::PostgreSql166() line 85
- class-const QueryMisuseRule::MergeInWith() line 86
- class-const QueryMisuseRule::SearchOrCycleNotRecursive() line 89
- method-call Derivation::query() line 91
- method-call CommonTableFacts::level() line 91
- method-call CommonTableFacts::shape() line 92
public function level(Environment $outer, list<CommonBinding> $bindings): EnvironmentAnswers an environment with more common tables at the same query level.
Parameters
$outer | Environment | |
$bindings | list<CommonBinding> |
Returns
Test cases 1
Called from 2
- method-call SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\CommonTableFacts::bind() packages/sql-semantics-postgres/src/Rules/Query/Facts/CommonTableFacts.php:91
- method-call SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\CommonTableFacts::bind() packages/sql-semantics-postgres/src/Rules/Query/Facts/CommonTableFacts.php:95
Calls 1
- new Environment line 105
public function uses(CommonTableExpression $table, Derivation $derivation): array<string, true>Answers the folded names of the unqualified relations a table's statement reads.
Parameters
$table | CommonTableExpression | |
$derivation | Derivation |
Returns
array<string, true>Test cases 1
Called from 1
Calls 2
- method-call ValueGraph::objects() line 116
- new ValueGraph line 116
public function order(
WithClause $with,
array<int, array<string, true>> $uses,
Derivation $derivation,
): list<int>Answers the order the tables are derived in: written order, or with RECURSIVE every table after the tables it refers to.
Parameters
$with | WithClause | |
$uses | array<int, array<string, true>> | |
$derivation | Derivation |
Returns
list<int>Called from 1
Calls 6
- function-call
array_keysline 134 - method-call Derivation::report() line 152
- new QueryMisuse line 152
- class-const QueryMisuseRule::MutualRecursion() line 152
- function-call
array_valuesline 157 - function-call
array_diffline 157
public function recursiveForm(CommonTableExpression $table): boolTells whether a recursive table has the form non-recursive part UNION [ALL] recursive part.
Parameters
$table | CommonTableExpression |
Returns
boolCalled from 1
Calls 3
- method-call Carriers::core() line 168
- new Carriers line 168
- class-const SetOperator::Union() line 170
public function shape(
CommonTableExpression $table,
QueryFact $fact,
Derivation $derivation,
): RowShapeAnswers the columns of a table: the output of its statement renamed by its column list, then the SEARCH and CYCLE columns.
Parameters
$table | CommonTableExpression | |
$fact | QueryFact | |
$derivation | Derivation |
Returns
Called from 1
Calls 17
- method-call ColumnAliases::fromQuery() line 178
- new ColumnAliases line 178
- function-call
countline 179 - method-call Derivation::report() line 180
- new ArityMismatch line 180
- class-const ArityRule::CommonTableColumns() line 180
- new OutputSlot line 185
- new RowShape line 187
- method-call CommonTableFacts::member() line 189
- class-const QueryMisuseRule::SearchColumnMissing() line 189
- new Known line 190
- class-const SearchOrder::Depth() line 190
- new ArrayOf line 190
- class-const Builtin::Record() line 190
- class-const Nullability::NotNull() line 190
- class-const QueryMisuseRule::CycleColumnMissing() line 193
- method-call CommonTableFacts::mark() line 194
public function mark(CommonTableExpression $table, Derivation $derivation): TypeFactDerives the mark values of a CYCLE clause and answers the type of the mark column.
Parameters
$table | CommonTableExpression | |
$derivation | Derivation |
Returns
Called from 1
Calls 7
- new Known line 208
- class-const Builtin::Bool() line 208
- new Environment line 210
- method-call Derivation::scalar() line 211
- method-call Unification::resolve() line 212
- new Unification line 212
- method-call Derivation::report() line 214
public function member(
RowShape $shape,
list<Name> $columns,
QueryMisuseRule $rule,
Derivation $derivation,
): voidReports the names of a SEARCH or CYCLE clause that are not columns of the table, when its columns are known.
Parameters
$shape | RowShape | |
$columns | list<Name> | |
$rule | QueryMisuseRule | |
$derivation | Derivation |
Called from 2
- method-call SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\CommonTableFacts::shape() packages/sql-semantics-postgres/src/Rules/Query/Facts/CommonTableFacts.php:189
- method-call SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\CommonTableFacts::shape() packages/sql-semantics-postgres/src/Rules/Query/Facts/CommonTableFacts.php:193
Calls 3
- method-call RowShape::complete() line 227
- method-call Derivation::report() line 236
- new QueryMisuse line 236
Test cases 2§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.