classLikeClause
final class LikeClause
implements Clause
uses Snapshot
@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.
$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> $optionspublic QualifiedName $tableMethods§
public function __construct(public QualifiedName $table, list<LikeOption> $options = [])Parameters
$table | QualifiedName | The source table |
$options | list<LikeOption> | The options in the order written |
Calls 2
- static-call Check::listOf() line 53
- class-const LikeOption::class() line 53
public function deriveClause(Derivation $derivation, Environment $environment): voidResolves the source table and records it as the relation fact of the clause.
Parameters
$derivation | Derivation | |
$environment | Environment |
Calls 11
- new RelationKinds line 61
- method-call RelationKinds::of() line 62
- method-call Derivation::target() line 62
- method-call Targets::resolve() line 62
- new Targets line 62
- method-call RelationKinds::require() line 63
- class-const RelationKind::BaseTable() line 63
- class-const RelationKind::View() line 63
- class-const RelationKind::MaterializedView() line 63
- class-const RelationKind::ForeignTable() line 63
- class-const KindRule::LikeSource() line 63
public function render(Output $out): voidWrites LIKE, the table and the options.
Parameters
$out | Output |
Calls 4
- method-call Output::keyword() line 71
- method-call Spelling::qualified() line 72
- new Spelling line 72
- method-call Output::node() line 74
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
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Table\Definition\Declarations::listed() packages/sql-semantics-postgres/src/Rules/Table/Definition/Declarations.php:90
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Table\Definition\Definitions::report() packages/sql-semantics-postgres/src/Rules/Table/Definition/Definitions.php:146
- instanceof SqlSemantics\Platform\PostgreSql\Statement\Table\Element\ListedColumns::__construct() packages/sql-semantics-postgres/src/Statement/Table/Element/ListedColumns.php:48
Type declarations 3
- type SqlSemantics\Platform\PostgreSql\Lowering\Table\ColumnRule packages/sql-semantics-postgres/src/Lowering/Table/ColumnRule.php:320
- type SqlSemantics\Platform\PostgreSql\Rules\Table\Definition\Declarations packages/sql-semantics-postgres/src/Rules/Table/Definition/Declarations.php:110
- type SqlSemantics\Platform\PostgreSql\Rules\Table\Definition\Declarations packages/sql-semantics-postgres/src/Rules/Table/Definition/Declarations.php:131