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.

Declaring a sequencedoctest
$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> $options
public Persistence $persistence = Persistence::Permanent
public bool $ifNotExists = false

Methods§

public function __construct(
    public QualifiedName $name,
    list<SequenceOption> $options = [],
    public Persistence $persistence = Persistence::Permanent,
    public bool $ifNotExists = false,
)

Parameters

$nameQualifiedNameThe sequence name
$optionslist<SequenceOption>The options in the order written
$persistencePersistenceThe persistence
$ifNotExistsboolWhether IF NOT EXISTS is written
Calls 3
public function createdSchema(): ?Name

Answers the schema written on the sequence name.

Returns

public function deriveStatement(Derivation $derivation): void

Derives the options and provides the declaration.

Parameters

$derivationDerivation
Calls 2
public function deriveElement(Derivation $derivation, Name $schema): void

Derives the statement inside CREATE SCHEMA: an unqualified sequence belongs to that schema.

Parameters

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

Writes the statement.

Parameters

$outOutput
Calls 5

Test cases 1§

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

Dedicated tests 1

Relations§

Instantiated in 1
Constant reads 1
Type declarations 2