final class LikeClause
    implements Clause
    uses Snapshot
Public API: explicitly declared with @visibility public.

A LIKE clause: the new table takes the columns of another table at this position.

Mirrors PostgreSQL's TableLikeClause with its options in the order written. The source table is resolved (PG-TABLE-TARGET-001) and is the relation fact of this clause, and a sequence is no valid source (PG-RELATION-KIND-001); the new table declares the source's columns, types and NOT NULL facts when the source is declared, and is incomplete from this position on otherwise (PG-TABLE-DECLARATION-001). Source: https://www.postgresql.org/docs/17/sql-createtable.html.

Copying the columns of a declared tabledoctest
$semantics = new \SqlSemantics\Platform\PostgreSql\Semantics();
    $source = $semantics->analyze('CREATE TABLE u (id int NOT NULL, name text)', []);
    $copy = $semantics->analyze('CREATE TABLE t (LIKE u INCLUDING DEFAULTS, extra boolean)', $source->declarations());
    array_map(static fn ($column) => $column->name->value, $copy->declarations()[0]->columns) // => ['id', 'name', 'extra']

Properties§

public list<LikeOption> $options
public QualifiedName $table

Methods§

public function __construct(public QualifiedName $table, list<LikeOption> $options = [])

Parameters

$tableQualifiedNameThe source table
$optionslist<LikeOption>The options in the order written
Calls 2
public function deriveClause(Derivation $derivation, Environment $environment): void

Resolves the source table and records it as the relation fact of the clause.

Parameters

$derivationDerivation
$environmentEnvironment
Calls 11
public function render(Output $out): void

Writes LIKE, the table and the options.

Parameters

$outOutput
Calls 4

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
Type checks 3
Type declarations 3