classRename
final class Rename
implements Statement
uses Snapshot
@visibility public.ALTER kind object RENAME [part name] TO new_name: renames an object or one of its columns, constraints or attributes.
Mirrors PostgreSQL's RenameStmt (renameType, relationType, object, subname, newname, behavior, missing_ok). How the object is named depends on the kind (PG-OBJECT-FORM-001). A renamed relation is resolved; renaming a column the declared relation lacks, or to a name it has, is reported. Renaming changes no declaration of the context. Source: https://www.postgresql.org/docs/17/sql-altertable.html, https://www.postgresql.org/docs/17/sql-alterfunction.html.
$operation = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('ALTER TABLE t RENAME COLUMN a TO b');
[$operation->statement->member?->name->value, $operation->statement->newName->value] // => ['a', 'b']Properties§
public ObjectKind $kindpublic ObjectReference $objectpublic Name $newNamepublic RenamedMember|null $member = nullpublic bool $ifExists = falsepublic DropBehavior|null $behavior = nullpublic RoleWord|null $roleWord = nullMethods§
public function __construct(
public ObjectKind $kind,
public ObjectReference $object,
public Name $newName,
public RenamedMember|null $member = null,
public bool $ifExists = false,
public DropBehavior|null $behavior = null,
public RoleWord|null $roleWord = null,
)Parameters
$kind | ObjectKind | The kind of the object |
$object | ObjectReference | The object, named as ALTER ... RENAME names objects of the kind |
$newName | Name | The new name |
$member | RenamedMember|null | The renamed column, constraint or attribute, if the object itself is not renamed |
$ifExists | bool | Whether IF EXISTS is written |
$behavior | DropBehavior|null | CASCADE or RESTRICT, written only when renaming an attribute |
$roleWord | RoleWord|null | The keyword naming a role; given exactly for roles |
Calls 12
- new ObjectForms line 61
- static-call Check::input() line 62
- function-call
in_arrayline 62 - method-call ObjectForms::form() line 62
- method-call ObjectForms::altered() line 62
- class-const ObjectKind::Role() line 63
- class-const ObjectKind::Policy() line 64
- class-const ObjectForms::ALTERED_RELATION() line 64
- class-const RenamedPart::Column() line 66
- class-const RenamedPart::Constraint() line 67
- class-const RenamedPart::Attribute() line 68
- class-const ObjectKind::Table() line 70
public function deriveStatement(Derivation $derivation): voidDerives the object and reports a renamed column the declared relation lacks or a new column name it has.
Parameters
$derivation | Derivation |
Calls 9
- method-call ObjectFacts::derive() line 79
- new ObjectFacts line 79
- method-call RelationKinds::renamed() line 80
- new RelationKinds line 80
- class-const RenamedPart::Attribute() line 80
- class-const RenamedPart::Column() line 81
- new RelationTargets line 82
- method-call RelationTargets::member() line 83
- method-call RelationTargets::renamed() line 84
public function render(Output $out): voidWrites the statement.
Parameters
$out | Output |
Calls 5
- method-call Output::keyword() line 93
- method-call ObjectSpelling::kind() line 97
- new ObjectSpelling line 97
- method-call Output::node() line 102
- class-const NameUse::Column() line 102
Test cases 7§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 6
RenameTest::testRejectsABehaviorWithoutAnAttributecallsRenameTest::testRejectsADomainConstraintUnderIfExistscallsRenameTest::testRejectsAPartOfAnotherKindcallsRenameTest::testRejectsARoleWithoutItsKeywordcallsRenameTest::testRejectsIfExistsOfAnotherKindcallsRenameTest::testRejectsRoleWordForAnotherKindcalls