classDefine
final class Define
implements Statement
uses Snapshot
@visibility public.CREATE kind name [arguments] ( definition ): defines an aggregate, operator, base or shell type, text search object or collation.
Mirrors PostgreSQL's DefineStmt (kind, oldstyle, defnames, args, definition, if_not_exists, replace). The definition is the list of attributes in written order, each read the way the command for the kind reads it (DefineAggregate, DefineOperator, DefineType, DefineCollation or the text search commands): the function of an operator is a routine name, its argument types are types. An aggregate is written with its argument list, or in the old style without one, where every attribute has a value and its name is an identifier. CREATE TYPE name alone defines a shell type. Source: https://www.postgresql.org/docs/17/sql-createaggregate.html, https://www.postgresql.org/docs/17/sql-createoperator.html, https://www.postgresql.org/docs/17/sql-createtype.html, https://www.postgresql.org/docs/17/sql-createtsdictionary.html, https://www.postgresql.org/docs/17/sql-createcollation.html.
$operation = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('CREATE OPERATOR === (leftarg = int4, rightarg = int4, function = int4eq)');
[$operation->statement->kind->value, count($operation->statement->definition ?? [])] // => ['OPERATOR', 3]Properties§
public list<Attribute>|null $definitionpublic ObjectKind $kindpublic DottedName|OperatorName $namepublic AggregateArguments|null $arguments = nullpublic bool $replace = falsepublic bool $ifNotExists = falseMethods§
public function __construct(
public ObjectKind $kind,
public DottedName|OperatorName $name,
list<Attribute>|null $definition,
public AggregateArguments|null $arguments = null,
public bool $replace = false,
public bool $ifNotExists = false,
)Parameters
$kind | ObjectKind | AGGREGATE, OPERATOR, TYPE, one of the four text search kinds, or COLLATION |
$name | DottedName|OperatorName | The object name; an operator for OPERATOR |
$definition | list<Attribute>|null | The attributes of the kind's command, at least one; null for a shell type |
$arguments | AggregateArguments|null | The argument list of an aggregate; null for an old-style aggregate and other kinds |
$replace | bool | Whether OR REPLACE is written; aggregates only |
$ifNotExists | bool | Whether IF NOT EXISTS is written; collations only |
Calls 14
- static-call Check::input() line 68
- function-call
in_arrayline 68 - class-const ObjectKind::Aggregate() line 68
- class-const ObjectKind::Operator() line 68
- class-const ObjectKind::Type() line 68
- class-const ObjectKind::TextSearchParser() line 68
- class-const ObjectKind::TextSearchDictionary() line 68
- class-const ObjectKind::TextSearchTemplate() line 68
- class-const ObjectKind::TextSearchConfiguration() line 68
- class-const ObjectKind::Collation() line 68
- static-call Check::listOf() line 71
- class-const Attribute::class() line 71
- method-call AttributeReader::command() line 72
- new AttributeReader line 72
public function deriveStatement(Derivation $derivation): voidDerives the arguments and attributes and reports the attribute problems the command reports.
Parameters
$derivation | Derivation |
Calls 3
- method-call Derivation::environment() line 87
- method-call DefineChecks::derive() line 92
- new DefineChecks line 92
public function render(Output $out): voidWrites the statement.
Parameters
$out | Output |
Calls 8
- method-call Output::keyword() line 100
- method-call ObjectSpelling::kind() line 104
- new ObjectSpelling line 104
- method-call Output::node() line 108
- class-const ObjectKind::Aggregate() line 109
- method-call Output::symbol() line 110
- method-call Output::name() line 115
- class-const NameUse::Identifier() line 115
Test cases 12§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 10
DefineTest::testDeriveStatementReadsTheFunctionOfAnOperatorAsARoutinecallsDefineTest::testRejectsAnAttributeOfAnotherCommandcallsDefineTest::testRejectsAnOldStyleAttributeWithoutValuecallsDefineTest::testRejectsAnOperatorNamedByADottedNamecallsDefineTest::testRejectsAnotherKindcallsDefineTest::testRejectsAnUnrecognizedAttributeTheCommandKnowscallsDefineTest::testRejectsArgumentsOfAnotherKindcallsDefineTest::testRejectsAShellOfAnotherKindcallsDefineTest::testRejectsIfNotExistsOfAnotherKindcallsDefineTest::testRejectsReplaceOfAnotherKindcalls
Other tests reaching this symbol 2
Relations§
Instantiated in 8
- new SqlSemantics\Platform\PostgreSql\Lowering\Routine\DefineRule::define() packages/sql-semantics-postgres/src/Lowering/Routine/DefineRule.php:72
- new SqlSemantics\Platform\PostgreSql\Lowering\Routine\DefineRule::define() packages/sql-semantics-postgres/src/Lowering/Routine/DefineRule.php:76
- new SqlSemantics\Platform\PostgreSql\Lowering\Routine\DefineRule::define() packages/sql-semantics-postgres/src/Lowering/Routine/DefineRule.php:77
- new SqlSemantics\Platform\PostgreSql\Lowering\Routine\DefineRule::define() packages/sql-semantics-postgres/src/Lowering/Routine/DefineRule.php:78
- new SqlSemantics\Platform\PostgreSql\Lowering\Routine\DefineRule::define() packages/sql-semantics-postgres/src/Lowering/Routine/DefineRule.php:79
- new SqlSemantics\Platform\PostgreSql\Lowering\Routine\DefineRule::define() packages/sql-semantics-postgres/src/Lowering/Routine/DefineRule.php:80
- new SqlSemantics\Platform\PostgreSql\Lowering\Routine\DefineRule::type() packages/sql-semantics-postgres/src/Lowering/Routine/DefineRule.php:99
- new SqlSemantics\Platform\PostgreSql\Lowering\Routine\DefineRule::type() packages/sql-semantics-postgres/src/Lowering/Routine/DefineRule.php:100