final class CopyTable
    implements Statement
    uses Snapshot
Public API: explicitly declared with @visibility public.

COPY between a table and a file, a program or the client.

Mirrors PostgreSQL's CopyStmt with a relation (relation, attlist, is_from, is_program, filename, options, whereClause). The options are those of the old syntax, written one after another, or the generic ones in parentheses; BINARY after COPY and DELIMITERS are old-syntax options too. The facts follow PG-COPY-001. Source: https://www.postgresql.org/docs/17/sql-copy.html. Status: Implemented.

Reading a COPY of a tabledoctest
$copy = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze("COPY t (a) FROM PROGRAM 'cat x' WITH (format csv) WHERE a > 0");
    [$copy->statement->program, $copy->statement->file->value, $copy->toString()] // => [true, 'cat x', "COPY t (a) FROM PROGRAM 'cat x' (format csv) WHERE a > 0"]
Refusing both kinds of optionsdoctest
new \SqlSemantics\Platform\PostgreSql\Statement\Manipulation\Copy\CopyTable(false, new \SqlSemantics\Platform\PostgreSql\Statement\Manipulation\TargetTable(new \SqlSemantics\Platform\PostgreSql\Statement\Name\RelationReference(new \SqlSemantics\Platform\PostgreSql\Model\Statement\Identifier\QualifiedName(new \SqlSemantics\Platform\PostgreSql\Model\Statement\Identifier\Name('t')))), [], \SqlSemantics\Platform\PostgreSql\Statement\Manipulation\Copy\CopyDirection::To, false, \SqlSemantics\Platform\PostgreSql\Statement\Manipulation\Copy\CopyStream::Stdout, null, [\SqlSemantics\Platform\PostgreSql\Statement\Manipulation\Copy\CopyFlag::Csv], [new \SqlSemantics\Platform\PostgreSql\Statement\Manipulation\Copy\CopyOption(new \SqlSemantics\Platform\PostgreSql\Model\Statement\Identifier\Name('header'))]) // throws \SqlSemantics\Platform\PostgreSql\Model\Diagnostic\InvalidConstruction

Properties§

public list<Name> $columns
public list<CopyFlag|CopyText|CopyForce> $legacy
public list<CopyOption> $options
public bool $binary
public TargetTable $table
public CopyDirection $direction
public bool $program
public StringConstant|null $delimiters = null
public Scalar|null $where = null

Methods§

public function __construct(
    public bool $binary,
    public TargetTable $table,
    list<Name> $columns,
    public CopyDirection $direction,
    public bool $program,
    public StringConstant|CopyStream $file,
    public StringConstant|null $delimiters = null,
    list<CopyFlag|CopyText|CopyForce> $legacy = [],
    list<CopyOption> $options = [],
    public Scalar|null $where = null,
)

Parameters

$binaryboolWhether BINARY is written after COPY
$tableTargetTableThe table; never with ONLY or an alias
$columnslist<Name>The columns copied, in written order
$directionCopyDirectionFROM or TO
$programboolWhether the file is a program
$fileStringConstant|CopyStreamThe file name or command, or the client
$delimitersStringConstant|nullThe string of the old DELIMITERS option
$legacylist<CopyFlag|CopyText|CopyForce>The options of the old syntax
$optionslist<CopyOption>The parenthesized options
$whereScalar|nullThe condition rows must meet to be copied

Throws

InvalidConstruction When the table has ONLY or an alias, both kinds of options are written, or a list holds a foreign item
Calls 9
public function deriveStatement(Derivation $derivation): void

Derives the table, the columns, the options and the condition.

Parameters

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

Writes the statement.

Parameters

$outOutput
Calls 5

Test cases 14§

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

Dedicated tests 1
Other tests reaching this symbol 13

Relations§

Instantiated in 1
Type declarations 3