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

COPY of the rows of a query to a file, a program or the client.

Mirrors PostgreSQL's CopyStmt with a query. The query is a query statement or a data-modifying statement with RETURNING. The facts follow PG-COPY-001. Source: https://www.postgresql.org/docs/17/sql-copy.html. Status: Implemented.

Reading a COPY of a querydoctest
$copy = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze("COPY (SELECT 1) TO '/tmp/x' CSV");
    [$copy->statement->query instanceof \SqlSemantics\Platform\PostgreSql\Statement\Query\Select, $copy->toString()] // => [true, "COPY (SELECT 1) TO '/tmp/x' CSV"]

Properties§

public list<CopyFlag|CopyText|CopyForce> $legacy
public list<CopyOption> $options
public Query $query
public bool $program

Methods§

public function __construct(
    public Query $query,
    public bool $program,
    public StringConstant|CopyStream $file,
    list<CopyFlag|CopyText|CopyForce> $legacy = [],
    list<CopyOption> $options = [],
)

Parameters

$queryQueryThe query: a query statement or a data-modifying statement
$programboolWhether the file is a program
$fileStringConstant|CopyStreamThe file name or command, or the client
$legacylist<CopyFlag|CopyText|CopyForce>The options of the old syntax
$optionslist<CopyOption>The parenthesized options

Throws

InvalidConstruction When the query is no statement, both kinds of options are written, or a list holds a foreign item
Calls 10
public function deriveStatement(Derivation $derivation): void

Derives the query and the options.

Parameters

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

Writes the statement.

Parameters

$outOutput
Calls 3

Test cases 2§

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 1

Relations§

Instantiated in 1
Type declarations 2