classCommonTableExpression
final class CommonTableExpression
implements RecursiveDefinition
uses Snapshot
Public API: explicitly declared with
@visibility public.One common table expression: a name, optional column names, and the statement that computes its rows.
Mirrors PostgreSQL's CommonTableExpr. The statement is a query or a data-modifying statement, whose rows are its RETURNING list. The WITH clause that holds the expression binds it (PG-COMMON-TABLE-001). Source: https://www.postgresql.org/docs/17/queries-with.html.
$one = new \SqlSemantics\Platform\PostgreSql\Statement\Query\Select([new \SqlSemantics\Platform\PostgreSql\Statement\Query\ExpressionTarget(new \SqlSemantics\Platform\PostgreSql\Statement\Literal\Constant(new \SqlSemantics\Platform\PostgreSql\Statement\Literal\IntegerConstant('1')))]);
$table = new \SqlSemantics\Platform\PostgreSql\Statement\Query\With\CommonTableExpression(new \SqlSemantics\Platform\PostgreSql\Model\Statement\Identifier\Name('x'), $one, [new \SqlSemantics\Platform\PostgreSql\Model\Statement\Identifier\Name('a')], \SqlSemantics\Platform\PostgreSql\Statement\Query\With\Materialization::Materialized);
[$table->name->value, $table->columns[0]->value, $table->materialization->value] // => ['x', 'a', 'MATERIALIZED']Properties§
public list<Name> $columnspublic Name $namepublic Query $querypublic Materialization|null $materialization = nullpublic SearchClause|null $search = nullpublic CycleClause|null $cycle = nullMethods§
public function __construct(
public Name $name,
public Query $query,
list<Name> $columns = [],
public Materialization|null $materialization = null,
public SearchClause|null $search = null,
public CycleClause|null $cycle = null,
)Parameters
$name | Name | The name the statement refers to the table by |
$query | Query | The query or data-modifying statement that computes the rows |
$columns | list<Name> | The column names written after the name |
$materialization | Materialization|null | Whether the rows are computed once, as written |
$search | SearchClause|null | The SEARCH clause of a recursive query |
$cycle | CycleClause|null | The CYCLE clause of a recursive query |
Calls 3
- static-call Check::input() line 54
- static-call Check::listOf() line 55
- class-const Name::class() line 55
public function recursiveQuery(): QueryAnswers the statement that computes the rows.
Returns
public function recursiveColumns(): list<Name>Answers the column names written after the name.
Returns
list<Name>public function render(Output $out): voidWrites the name, the columns, AS, the materialization, the statement in parentheses and the SEARCH and CYCLE clauses.
Parameters
$out | Output |
Test cases 1
Calls 5
- method-call Output::name() line 81
- class-const NameUse::Column() line 81
- method-call Output::symbol() line 83
- method-call Output::keyword() line 92
- function-call
explodeline 94
Test cases 16§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 3
Other tests reaching this symbol 13
CommonTableFactsTest::testBindMakesTheTablesVisiblecallsCommonTableFactsTest::testMarkIsTheCommonTypeOfTheValuescallsCommonTableFactsTest::testMemberReportsASearchColumnTheTableLackscallsCommonTableFactsTest::testOrderDerivesReferencedTablesFirstcallsCommonTableFactsTest::testRecursiveFormReportsAQueryWithoutUnioncallsCommonTableFactsTest::testShapeAddsTheSearchAndCycleColumnscallsCommonTableFactsTest::testUsesListsTheReadRelationscallsSetOperationFactsTest::testReboundBindsTheRecursiveTablecallsTableShapesTest::testInputReportsASampleOfACommonTablecallsRecursiveDefinitionTest::testRecursiveColumnsAreTheWrittenNamescallsRecursiveDefinitionTest::testRecursiveQueryIsTheComputingQuerycallsWithClauseTest::testDeriveCommonTablesBindsTheTablescallsWithClauseTest::testRenderWritesRecursivecalls
Relations§
Instantiated in 1
Constant reads 1
Type checks 1
Type declarations 4
- type SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\CommonTableFacts packages/sql-semantics-postgres/src/Rules/Query/Facts/CommonTableFacts.php:113
- type SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\CommonTableFacts packages/sql-semantics-postgres/src/Rules/Query/Facts/CommonTableFacts.php:166
- type SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\CommonTableFacts packages/sql-semantics-postgres/src/Rules/Query/Facts/CommonTableFacts.php:176
- type SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\CommonTableFacts packages/sql-semantics-postgres/src/Rules/Query/Facts/CommonTableFacts.php:204