classCopyTable
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.
$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"]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\InvalidConstructionProperties§
public list<Name> $columnspublic list<CopyOption> $optionspublic bool $binarypublic TargetTable $tablepublic CopyDirection $directionpublic bool $programpublic StringConstant|CopyStream $filepublic StringConstant|null $delimiters = nullpublic Scalar|null $where = nullMethods§
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
$binary | bool | Whether BINARY is written after COPY |
$table | TargetTable | The table; never with ONLY or an alias |
$columns | list<Name> | The columns copied, in written order |
$direction | CopyDirection | FROM or TO |
$program | bool | Whether the file is a program |
$file | StringConstant|CopyStream | The file name or command, or the client |
$delimiters | StringConstant|null | The string of the old DELIMITERS option |
$legacy | list<CopyFlag|CopyText|CopyForce> | The options of the old syntax |
$options | list<CopyOption> | The parenthesized options |
$where | Scalar|null | The 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 itemCalls 9
- static-call Check::input() line 83
- static-call Check::listOf() line 84
- class-const Name::class() line 84
- method-call ClosedList::of() line 85
- new ClosedList line 85
- class-const CopyFlag::class() line 85
- class-const CopyText::class() line 85
- class-const CopyForce::class() line 85
- class-const CopyOption::class() line 86
public function deriveStatement(Derivation $derivation): voidDerives the table, the columns, the options and the condition.
Parameters
$derivation | Derivation |
Calls 2
- method-call CopyFacts::table() line 95
- new CopyFacts line 95
public function render(Output $out): voidWrites the statement.
Parameters
$out | Output |
Calls 5
- method-call Output::keyword() line 103
- method-call Output::node() line 107
- method-call AliasSpelling::names() line 108
- new AliasSpelling line 108
- method-call Output::symbol() line 121
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
CopyOptionRuleTest::testArgumentLowersEveryFormcallsCopyOptionRuleTest::testArgumentsLowersTheItemscallsCopyOptionRuleTest::testItemLowersAForceColumnListcallsCopyOptionRuleTest::testOptionLowersTheNamecallsCopyOptionRuleTest::testOptionsLowersTheOldSyntaxcallsCopyRuleTest::testDelimitersLowersTheStringcallsCopyRuleTest::testDirectionLowersFromcallsCopyRuleTest::testFileLowersAFileNamecallsCopyRuleTest::testFlagLowersBinaryAndProgramcallsManipulationsTest::testStatementRoutesEveryStatementOfTheFamilycallsCopyOptionsTest::testListedAnswersTheColumnsOfAListArgumentcallsCopyForceTest::testOptionAnswersTheGenericOptioncallsCopyTextTest::testOptionAnswersTheGenericOptioncalls
Relations§
Instantiated in 1
Type declarations 3
- type SqlSemantics\Platform\PostgreSql\Lowering\Manipulation\CopyRule packages/sql-semantics-postgres/src/Lowering/Manipulation/CopyRule.php:45
- type SqlSemantics\Platform\PostgreSql\Rules\Manipulation\CopyFacts packages/sql-semantics-postgres/src/Rules/Manipulation/CopyFacts.php:51
- type SqlSemantics\Platform\PostgreSql\Rules\Manipulation\CopyFacts packages/sql-semantics-postgres/src/Rules/Manipulation/CopyFacts.php:79