classIndirection
final class Indirection
implements Scalar, OutputNaming
uses Snapshot
@visibility public.Field selections, subscripts and slices applied to a value: (x).f, $1[2], a[1:2], (SELECT …).f.
Mirrors PostgreSQL's A_Indirection node. The grammar applies steps to a parenthesized expression, a parameter, a scalar subquery, and a column reference once a subscript follows its dotted name; a dotted name that ends in .* is a ColumnStar, which takes further steps only improperly.
Rule: PG-INDIRECTION-001. Facts follow PG-SUBSCRIPT-001. An unaliased result column is named after the last field the steps select, and otherwise as the base names it. Source: https://www.postgresql.org/docs/17/sql-expressions.html#SQL-EXPRESSIONS-SUBSCRIPTS, https://www.postgresql.org/docs/17/sql-expressions.html#FIELD-SELECTION. Status: Implemented.
$query = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('SELECT (ROW(1, 2)).f2');
[$query->field(0)->name->value, $query->field(0)->type->descriptor->name()] // => ['f2', 'integer']$a = new \SqlSemantics\Platform\PostgreSql\Statement\Expression\ColumnReference([new \SqlSemantics\Platform\PostgreSql\Model\Statement\Identifier\Name('a')]);
new \SqlSemantics\Platform\PostgreSql\Statement\Expression\Indirection($a, [new \SqlSemantics\Platform\PostgreSql\Statement\Expression\FieldSelection(new \SqlSemantics\Platform\PostgreSql\Model\Statement\Identifier\Name('b'))]) // throws \SqlSemantics\Platform\PostgreSql\Model\Diagnostic\InvalidConstructionProperties§
public non-empty-list<IndirectionStep> $stepspublic Scalar $baseMethods§
public function __construct(public Scalar $base, list<IndirectionStep> $steps)Parameters
$base | Scalar | The value the steps apply to |
$steps | list<IndirectionStep> | The steps in order; at least one |
Calls 3
- static-call Check::listOf() line 61
- class-const IndirectionStep::class() line 61
- static-call Check::input() line 62
public function outputName(): ?NameNames an unaliased result column after the last selected field, or as the base does.
Returns
?NameTest cases 1
Calls 2
- method-call ColumnNaming::name() line 75
- new ColumnNaming line 75
public function deriveScalar(Derivation $derivation, Environment $environment): ScalarFactDerives the base and the steps, and the value the steps select.
Parameters
$derivation | Derivation | |
$environment | Environment |
Returns
Calls 3
- method-call Derivation::scalar() line 83
- method-call Subscripting::apply() line 88
- new Subscripting line 88
public function render(Output $out): voidWrites the base and the steps.
Parameters
$out | Output |
Test cases 1
Calls 1
- method-call Output::node() line 96
Test cases 9§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 5
IndirectionTest::testDeriveScalarSelectsAFieldOfARowcallsIndirectionTest::testOutputNameIsTheLastSelectedFieldcallsIndirectionTest::testRejectsABaseTheGrammarDoesNotIndirectcallsIndirectionTest::testRejectsAFieldStepRightAfterADottedNamecallsIndirectionTest::testRenderWritesTheBaseAndTheStepscalls
Other tests reaching this symbol 4
Relations§
Instantiated in 2
- new SqlSemantics\Platform\PostgreSql\Lowering\Expression\PrimaryRule::lower() packages/sql-semantics-postgres/src/Lowering/Expression/PrimaryRule.php:70
- new SqlSemantics\Platform\PostgreSql\Lowering\Expression\PrimaryRule::applied() packages/sql-semantics-postgres/src/Lowering/Expression/PrimaryRule.php:95
Type checks 4
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Expression\ColumnNaming::figure() packages/sql-semantics-postgres/src/Rules/Expression/ColumnNaming.php:68
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Table\Command\TriggerReferences::references() packages/sql-semantics-postgres/src/Rules/Table/Command/TriggerReferences.php:90
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Table\Command\TriggerReferences::selected() packages/sql-semantics-postgres/src/Rules/Table/Command/TriggerReferences.php:114
- instanceof SqlSemantics\Platform\PostgreSql\Statement\Query\ExpressionTarget::project() packages/sql-semantics-postgres/src/Statement/Query/ExpressionTarget.php:72