final class ExpressionKey
    implements Scalar
    uses Snapshot
Public API: explicitly declared with @visibility public.

An expression as the key of an index, a partition key or extended statistics.

Mirrors the expr of PostgreSQL's IndexElem, PartitionElem and StatsElem. The grammar takes a function call as written and any other expression between parentheses; which of the two is written is kept. The expression is derived where the columns of the relation are visible, and the key has its type and NULL fact. Source: https://www.postgresql.org/docs/17/sql-createindex.html.

Reading an expression keydoctest
$index = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('CREATE INDEX ON t ((a + 1), lower(b))');
    [$index->statement->elements[0]->key->parenthesized, $index->statement->elements[1]->key->parenthesized] // => [true, false]
Refusing an operator without parenthesesdoctest
new \SqlSemantics\Platform\PostgreSql\Statement\Table\Index\ExpressionKey(new \SqlSemantics\Platform\PostgreSql\Statement\Expression\Predicate\NullTest(new \SqlSemantics\Platform\PostgreSql\Statement\Expression\ColumnReference([new \SqlSemantics\Platform\PostgreSql\Model\Statement\Identifier\Name('a')]), false), false) // throws \SqlSemantics\Platform\PostgreSql\Model\Diagnostic\InvalidConstruction

Properties§

public Scalar $expression
public bool $parenthesized = true

Methods§

public function __construct(public Scalar $expression, public bool $parenthesized = true)

Parameters

$expressionScalarThe expression
$parenthesizedboolWhether the expression is written between parentheses; one that is not must be a function call
Calls 3
public function deriveScalar(Derivation $derivation, Environment $environment): ScalarFact

Derives the expression and answers its facts.

Parameters

$derivationDerivation
$environmentEnvironment

Returns

Calls 2
public function render(Output $out): void

Writes the expression, between parentheses when it is written so.

Parameters

$outOutput
Calls 2

Test cases 4§

Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.

Dedicated tests 2
Other tests reaching this symbol 2

Relations§

Instantiated in 6
Type checks 1
Type declarations 3