classIndexConstraint
final class IndexConstraint
implements Constraint
uses Snapshot
Public API: explicitly declared with
@visibility public.A UNIQUE or PRIMARY KEY constraint built on an existing unique index: USING INDEX name.
Mirrors CONSTR_UNIQUE/CONSTR_PRIMARY with indexname. The key columns are those of the index, which a context does not declare; the server accepts this form only in ALTER TABLE ... ADD. Source: https://www.postgresql.org/docs/17/sql-altertable.html.
$alter = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('ALTER TABLE t ADD CONSTRAINT k PRIMARY KEY USING INDEX i');
[$alter->statement->commands[0]->constraint->primary, $alter->statement->commands[0]->constraint->index->value] // => [true, 'i']Properties§
public list<ConstraintAttribute> $attributespublic bool $primarypublic Name $indexpublic Name|null $name = nullMethods§
public function __construct(
public bool $primary,
public Name $index,
list<ConstraintAttribute> $attributes = [],
public Name|null $name = null,
)Parameters
$primary | bool | Whether the constraint is a primary key; a unique constraint otherwise |
$index | Name | The index |
$attributes | list<ConstraintAttribute> | The attributes in the order written |
$name | Name|null | The constraint name |
Calls 2
- method-call Attributes::checked() line 48
- new Attributes line 48
public function kind(): ConstraintKindAnswers the kind of the constraint.
Returns
Calls 2
- class-const ConstraintKind::PrimaryKey() line 56
- class-const ConstraintKind::Unique() line 56
public function deriveClause(Derivation $derivation, Environment $environment): voidChecks the attributes.
Parameters
$derivation | Derivation | |
$environment | Environment |
Calls 2
- method-call Attributes::report() line 64
- new Attributes line 64
public function render(Output $out): voidWrites the constraint.
Parameters
$out | Output |
Calls 4
- new Writing line 72
- method-call Writing::constraintName() line 73
- method-call Output::keyword() line 74
- method-call Writing::sequence() line 75
Test cases 3§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 1
Other tests reaching this symbol 2
Relations§
Instantiated in 2
- new SqlSemantics\Platform\PostgreSql\Lowering\Table\ConstraintRule::element() packages/sql-semantics-postgres/src/Lowering/Table/ConstraintRule.php:112
- new SqlSemantics\Platform\PostgreSql\Lowering\Table\ConstraintRule::element() packages/sql-semantics-postgres/src/Lowering/Table/ConstraintRule.php:121
Constant reads 1
Type checks 3
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Table\Command\AlterKinds::relationWide() packages/sql-semantics-postgres/src/Rules/Table/Command/AlterKinds.php:178
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Table\Command\Alterations::identity() packages/sql-semantics-postgres/src/Rules/Table/Command/Alterations.php:103
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Table\Definition\Definitions::report() packages/sql-semantics-postgres/src/Rules/Table/Definition/Definitions.php:168