classCreateSequence
final class CreateSequence
implements SchemaElement
uses Snapshot
Public API: explicitly declared with
@visibility public.A request to create a sequence.
Mirrors PostgreSQL's CreateSeqStmt (sequence with its persistence, options, if_not_exists). A sequence is a relation: the statement provides its declaration (PG-SEQUENCE-001) with the columns last_value and log_cnt (bigint) and is_called (boolean), never NULL, and the system columns. Source: https://www.postgresql.org/docs/17/sql-createsequence.html.
$statement = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('CREATE TEMP SEQUENCE IF NOT EXISTS s AS bigint INCREMENT BY 2 START WITH 10 OWNED BY t.id');
[$statement->declarations()[0]->name->schema->value, $statement->declarations()[0]->columns[0]->name->value, $statement->toString()] // => ['pg_temp', 'last_value', 'CREATE TEMP SEQUENCE IF NOT EXISTS s AS BIGINT INCREMENT 2 START 10 OWNED BY t.id']Properties§
public list<SequenceOption> $optionspublic QualifiedName $namepublic Persistence $persistence = Persistence::Permanentpublic bool $ifNotExists = falseMethods§
public function __construct(
public QualifiedName $name,
list<SequenceOption> $options = [],
public Persistence $persistence = Persistence::Permanent,
public bool $ifNotExists = false,
)Parameters
$name | QualifiedName | The sequence name |
$options | list<SequenceOption> | The options in the order written |
$persistence | Persistence | The persistence |
$ifNotExists | bool | Whether IF NOT EXISTS is written |
Calls 3
- class-const Persistence::Permanent() line 50
- static-call Check::listOf() line 53
- class-const SequenceOption::class() line 53
public function deriveStatement(Derivation $derivation): voidDerives the options and provides the declaration.
Parameters
$derivation | Derivation |
Calls 2
- method-call Sequences::create() line 69
- new Sequences line 69
public function deriveElement(Derivation $derivation, Name $schema): voidDerives the statement inside CREATE SCHEMA: an unqualified sequence belongs to that schema.
Parameters
$derivation | Derivation | |
$schema | Name |
Calls 2
- method-call Sequences::create() line 77
- new Sequences line 77
public function render(Output $out): voidWrites the statement.
Parameters
$out | Output |
Calls 5
- method-call Output::keyword() line 85
- method-call Spelling::qualified() line 89
- new Spelling line 89
- method-call Writing::sequence() line 90
- new Writing line 90
Test cases 1§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.