classCopyFacts
final class CopyFacts
Derives the facts of COPY.
Rule: PG-COPY-001. The table follows PG-TARGET-TABLE-001; COPY TO reads only a table and COPY FROM writes neither a materialized view nor a sequence (PG-RELATION-KIND-001; cannot copy from view "v"). A column of the column list must be a column of the table, may be listed once and may not be a generated column (column "b" is a generated column, CopyGetAttnums, copy.c); without a list every column but the generated columns is copied. The WHERE condition sees the table and is allowed with COPY FROM only. The query of COPY TO is derived as a nested query; a data-modifying statement without RETURNING and a SELECT INTO are reported. PROGRAM with STDIN or STDOUT is reported. The options follow PG-COPY-OPTIONS-001. COPY returns no rows: the data goes to or comes from the file, the program or the client. Source: https://www.postgresql.org/docs/17/sql-copy.html, https://github.com/postgres/postgres/blob/REL_17_2/src/backend/commands/copy.c. Status: Implemented.
Methods§
public function table(CopyTable $copy, Derivation $derivation): voidDerives COPY of a table.
Parameters
$copy | CopyTable | |
$derivation | Derivation |
Called from 1
Calls 21
- method-call Derivation::environment() line 53
- method-call Derivation::relation() line 54
- method-call Targets::visible() line 55
- new Targets line 55
- method-call CopyFacts::kind() line 56
- method-call RelationKinds::of() line 56
- new RelationKinds line 56
- method-call CopyFacts::columns() line 57
- class-const CopyDirection::To() line 59
- method-call Derivation::report() line 60
- new ManipulationMisuse line 60
- class-const ManipulationMisuseRule::CopyWhereWithTo() line 60
- method-call Derivation::scalar() line 62
- new Environment line 62
- method-call CopyFacts::program() line 64
- method-call CopyOptions::check() line 65
- new CopyOptions line 65
- method-call CopyFacts::generated() line 65
- new Placement line 66
- method-call Placement::values() line 67
- method-call Placement::into() line 68
public function kind(CopyTable $copy, ?RelationKind $kind, Derivation $derivation): voidReports a relation of a kind COPY cannot read from or write into.
COPY TO reads only tables: a view, a materialized view, a foreign table or a sequence is refused. COPY FROM refuses a materialized view and a sequence; a view needs an INSTEAD OF INSERT trigger and a foreign table a wrapper that inserts, which the context does not tell.
Parameters
$copy | CopyTable | |
$kind | ?RelationKind | |
$derivation | Derivation |
Called from 1
Calls 14
- class-const CopyDirection::To() line 81
- class-const RelationKind::View() line 82
- class-const KindRule::CopyFromView() line 82
- class-const RelationKind::MaterializedView() line 83
- class-const KindRule::CopyFromMaterializedView() line 83
- class-const RelationKind::ForeignTable() line 84
- class-const KindRule::CopyFromForeignTable() line 84
- class-const RelationKind::Sequence() line 85
- class-const KindRule::CopyFromSequence() line 85
- class-const RelationKind::BaseTable() line 86
- class-const KindRule::CopyToMaterializedView() line 88
- class-const KindRule::CopyToSequence() line 89
- method-call Derivation::report() line 93
- new KindProblem line 93
public function query(CopyQuery $copy, Derivation $derivation): voidDerives COPY of a query.
Parameters
$copy | CopyQuery | |
$derivation | Derivation |
Called from 1
Calls 15
- method-call Derivation::query() line 102
- method-call Derivation::environment() line 102
- method-call Derivation::report() line 104
- new ManipulationMisuse line 104
- class-const ManipulationMisuseRule::CopyWithoutReturning() line 104
- method-call QueryRoots::first() line 106
- new QueryRoots line 106
- class-const ManipulationMisuseRule::CopySelectInto() line 108
- method-call CopyFacts::program() line 110
- method-call CopyOptions::check() line 117
- new CopyOptions line 117
- new Placement line 118
- method-call Placement::values() line 119
- method-call Placement::into() line 120
- method-call Placement::modifying() line 121
public function columns(
list<Name> $columns,
VisibleRelation $table,
Derivation $derivation,
): list<Name>|nullDerives the column list and answers the columns copied, or null when they are not known; the columns of a table without a list exclude its generated columns.
Parameters
$columns | list<Name> | |
$table | VisibleRelation | |
$derivation | Derivation |
Returns
list<Name>|nullCalled from 1
Calls 5
- method-call Derivation::report() line 145
- new ManipulationMisuse line 145
- class-const ManipulationMisuseRule::CopyGeneratedColumn() line 145
- class-const ManipulationMisuseRule::UnknownTargetColumn() line 148
- class-const ManipulationMisuseRule::RepeatedInsertColumn() line 152
public function generated(VisibleRelation $table): list<Name>Answers the names of the generated columns of a table.
Parameters
$table | VisibleRelation |
Returns
list<Name>public function program(
bool $program,
StringConstant|CopyStream $file,
Derivation $derivation,
): voidReports PROGRAM written with STDIN or STDOUT.
Parameters
$program | bool | |
$file | StringConstant|CopyStream | |
$derivation | Derivation |
Called from 2
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\CopyFacts::table() packages/sql-semantics-postgres/src/Rules/Manipulation/CopyFacts.php:64
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\CopyFacts::query() packages/sql-semantics-postgres/src/Rules/Manipulation/CopyFacts.php:110
Calls 3
- method-call Derivation::report() line 195
- new ManipulationMisuse line 195
- class-const ManipulationMisuseRule::CopyProgramWithClient() line 195
Test cases 1§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 1
CopyFactsTestcalls
Relations§
Instantiated in 2
- new SqlSemantics\Platform\PostgreSql\Statement\Manipulation\Copy\CopyQuery::deriveStatement() packages/sql-semantics-postgres/src/Statement/Manipulation/Copy/CopyQuery.php:69
- new SqlSemantics\Platform\PostgreSql\Statement\Manipulation\Copy\CopyTable::deriveStatement() packages/sql-semantics-postgres/src/Statement/Manipulation/Copy/CopyTable.php:95
Method calls 2
- method-call SqlSemantics\Platform\PostgreSql\Statement\Manipulation\Copy\CopyQuery::deriveStatement() packages/sql-semantics-postgres/src/Statement/Manipulation/Copy/CopyQuery.php:69
- method-call SqlSemantics\Platform\PostgreSql\Statement\Manipulation\Copy\CopyTable::deriveStatement() packages/sql-semantics-postgres/src/Statement/Manipulation/Copy/CopyTable.php:95