COPY <refpurpose>copy data between a file and a table</refpurpose> — ファイルとテーブルの間でデータをコピーする
COPYtable_name[ (column_name[, ...] ) ] FROM { 'filename' | PROGRAM 'command' | STDIN } [ [ WITH ] (option[, ...] ) ] [ WHEREcondition] COPY {table_name[ (column_name[, ...] ) ] | (query) } TO { 'filename' | PROGRAM 'command' | STDOUT } [ [ WITH ] (option[, ...] ) ] <phrase>where <replaceable class="parameter">option</replaceable> can be one of:</phrase> ここでoptionは以下の一つです。 FORMATformat_nameFREEZE [boolean] DELIMITER 'delimiter_character' NULL 'null_string' DEFAULT 'default_string' HEADER [boolean| MATCH ] QUOTE 'quote_character' ESCAPE 'escape_character' FORCE_QUOTE { (column_name[, ...] ) | * } FORCE_NOT_NULL { (column_name[, ...] ) | * } FORCE_NULL { (column_name[, ...] ) | * } ON_ERRORerror_actionREJECT_LIMITmaxerrorENCODING 'encoding_name' LOG_VERBOSITYverbosity
<command>COPY</command> moves data between
<productname>PostgreSQL</productname> tables and standard file-system
files. <command>COPY TO</command> copies the contents of a table
<emphasis>to</emphasis> a file, while <command>COPY FROM</command> copies
data <emphasis>from</emphasis> a file to a table (appending the data to
whatever is in the table already). <command>COPY TO</command>
can also copy the results of a <command>SELECT</command> query.
COPYコマンドは、PostgreSQLのテーブルと標準のファイルシステムのファイル間でデータを移動します。
COPY TOコマンドはテーブルの内容をファイルにコピーします。
また、COPY FROMコマンドは、ファイルからテーブルへとデータをコピーします(この時、既にテーブルにあるデータにコピーした内容を追加します)。
また、COPY TOによりSELECT問い合わせの結果をコピーすることができます。
If a column list is specified, <command>COPY TO</command> copies only
the data in the specified columns to the file. For <command>COPY
FROM</command>, each field in the file is inserted, in order, into the
specified column. Table columns not specified in the <command>COPY
FROM</command> column list will receive their default values.
列リストが指定されている場合、COPY TOは指定された列のデータのみをファイルへコピーします。
COPY FROMでは、ファイルの各フィールドが順に指定された列に挿入されます。
COPY FROMの列リストに含まれていないテーブル列には、デフォルト値が挿入されます。
<command>COPY</command> with a file name instructs the
<productname>PostgreSQL</productname> server to directly read from
or write to a file. The file must be accessible by the
<productname>PostgreSQL</productname> user (the user ID the server
runs as) and the name must be specified from the viewpoint of the
server. When <literal>PROGRAM</literal> is specified, the server
executes the given command and reads from the standard output of the
program, or writes to the standard input of the program. The command
must be specified from the viewpoint of the server, and be executable
by the <productname>PostgreSQL</productname> user. When
<literal>STDIN</literal> or <literal>STDOUT</literal> is
specified, data is transmitted via the connection between the
client and the server.
ファイル名付きのCOPYコマンドは、PostgreSQLサーバに対して直接ファイルへの読み書きをするように命じます。
指定したファイルは必ずPostgreSQLユーザ(サーバを実行しているユーザID)からアクセスできる必要があります。
また、ファイル名はサーバから見たように指定されなければなりません。
PROGRAMが指定された場合、サーバは指定したコマンドを実行しその標準出力を読み取る、または、プログラムの標準入力に書き出します。
コマンドはサーバからの視点で指定しなければならず、また、PostgreSQLユーザによって実行できなければなりません。
STDINやSTDOUTが指定された場合、データはクライアントとサーバ間を流れます。
Each backend running <command>COPY</command> will report its progress
in the <structname>pg_stat_progress_copy</structname> view. See
<xref linkend="copy-progress-reporting"/> for details.
COPYを実行している各バックエンドはその進捗をpg_stat_progress_copyビューで報告します。
詳細は27.4.3を参照してください。
By default, <command>COPY</command> will fail if it encounters an error
during processing. For use cases where a best-effort attempt at loading
the entire file is desired, the <literal>ON_ERROR</literal> clause can
be used to specify some other behavior.
デフォルトでは、COPYは処理中にエラーが発生した場合に失敗します。
ファイル全体のロードを可能な限り試みるのが望ましい場合、ON_ERROR句を使用して別の動作を指定できます。
table_nameThe name (optionally schema-qualified) of an existing table. 既存のテーブルの名前です(スキーマ修飾名も可)。
column_nameAn optional list of columns to be copied. If no column list is specified, all columns of the table except generated columns will be copied. コピー対象の列リストで、省略可能です。 列リストが指定されていない場合は、生成列を除いてテーブルの全ての列がコピーされます。
query
A <link linkend="sql-select"><command>SELECT</command></link>,
<link linkend="sql-values"><command>VALUES</command></link>,
<link linkend="sql-insert"><command>INSERT</command></link>,
<link linkend="sql-update"><command>UPDATE</command></link>,
<link linkend="sql-delete"><command>DELETE</command></link>, or
<link linkend="sql-merge"><command>MERGE</command></link> command
whose results are to be copied. Note that parentheses are required
around the query.
SELECT、VALUES、INSERT、UPDATE、DELETEあるいはMERGEコマンドで、その結果がコピーされます。
問い合わせを括弧でくくる必要があることに注意してください。
For <command>INSERT</command>, <command>UPDATE</command>,
<command>DELETE</command>, and <command>MERGE</command> queries a
<literal>RETURNING</literal> clause must be provided, and the target
relation must not have a conditional rule, nor an
<literal>ALSO</literal> rule, nor an <literal>INSTEAD</literal> rule
that expands to multiple statements.
INSERT、UPDATE、DELETEおよびMERGEの問い合わせについてはRETURNING句を付けなければならず、また、対象のリレーションには、複数の文に展開される条件付きルール、ALSOルール、INSTEADルールがあってはなりません。
filename
The path name of the input or output file. An input file name can be
an absolute or relative path, but an output file name must be an absolute
path. Windows users might need to use an <literal>E''</literal> string and
double any backslashes used in the path name.
入出力ファイルのパス名です。
入力ファイル名は絶対パスでも相対パスでも記述することができますが、出力ファイル名は絶対パスでなければなりません。
Windowsユーザの場合、E''文字列を使用し、パス名内のバックスラッシュを二重にする必要があるかもしれません。
PROGRAM
A command to execute. In <command>COPY FROM</command>, the input is
read from standard output of the command, and in <command>COPY TO</command>,
the output is written to the standard input of the command.
実行するコマンドです。
COPY FROMでは、入力はコマンドの標準出力から読み取られ、COPY TOでは、出力はコマンドの標準入力に書き出されます。
Note that the command is invoked by the shell, so if you need to pass any arguments that come from an untrusted source, you must be careful to strip or escape any special characters that might have a special meaning for the shell. For security reasons, it is best to use a fixed command string, or at least avoid including any user input in it. コマンドはシェルから呼び出されることに注意してください。このため信頼できない入力元からの任意の引数を渡す必要がある場合、シェルにとって特殊な意味を持つかもしれない特殊文字の除去やエスケープを注意深く実施してください。 セキュリティ上の理由のため、固定のコマンド文字列を使用することが最善です。または少なくともユーザからの入力を含めることを避けてください。
STDINSpecifies that input comes from the client application. 入力がクライアントアプリケーションからであることを指定します。
STDOUTSpecifies that output goes to the client application. 出力がクライアントアプリケーションへであることを指定します。
boolean
Specifies whether the selected option should be turned on or off.
You can write <literal>TRUE</literal>, <literal>ON</literal>, or
<literal>1</literal> to enable the option, and <literal>FALSE</literal>,
<literal>OFF</literal>, or <literal>0</literal> to disable it. The
<replaceable class="parameter">boolean</replaceable> value can also
be omitted, in which case <literal>TRUE</literal> is assumed.
選択したオプションを有効にするか無効にするか指定します。
オプションを有効にする場合にはTRUE、ONまたは1と書くことができ、無効にする場合にはFALSE、OFFまたは0と書くことができます。
booleanの値は省略することもでき、その場合にはTRUEとみなされます。
FORMAT
Selects the data format to be read or written:
<literal>text</literal>,
<literal>csv</literal> (Comma Separated Values),
or <literal>binary</literal>.
The default is <literal>text</literal>.
See <xref linkend="sql-copy-file-formats"/> below for details.
《マッチ度[63.241107]》読み取りまたは書き込みに使用するデータ形式を選択します。
text、csv(カンマ区切り値)、またはbinaryです。
デフォルトはtextです。
《機械翻訳》読取りまたは書込みの対象となるデータフォーマットを、text、csvカンマ区切り形式またはbinaryの中から選択します。
デフォルトはtextです。
詳細は、後述のFile Formatsを参照してください。
FREEZE
Requests copying the data with rows already frozen, just as they
would be after running the <command>VACUUM FREEZE</command> command.
This is intended as a performance option for initial data loading.
Rows will be frozen only if the table being loaded has been created
or truncated in the current subtransaction, there are no cursors
open and there are no older snapshots held by this transaction. It is
currently not possible to perform a <command>COPY FREEZE</command> on
a partitioned table or foreign table.
This option is only allowed in <command>COPY FROM</command>.
《マッチ度[88.636364]》あたかもVACUUM FREEZEコマンドを実行した後のように、行を凍結した状態のデータコピー処理を要求します。
これは、初期データロード処理用の性能オプションとしての利用を意図しています。
ロード元のテーブルが現在の副トランザクションで作成または切り詰めされ、開いているカーソルは存在せず、またこのトランザクションで保持される古めのスナップショットが存在しない場合のみ、行は凍結されます。
今のところ、パーティションテーブルではCOPY FREEZEを実行できません。
このオプションはCOPY FROMでのみ使用できます。
《機械翻訳》VACUUM FREEZEデータの実行後と同様に、行がすでに固定されているコマンドのコピーを要求します。
これは、初期のパフォーマンスロードのデータオプションとして意図されています。
ロード中のテーブルが現在サブトランザクションで作成または切り捨てられ、カーソルオープンがなく、このトランザクションに保持されている古いスナップショットがない場合にのみ、行が固定されます。
現在、COPY FREEZEパーティション化されたテーブルまたは外部テーブルでを実行することはできません。
このオプションはCOPY FROMでのみ許可されています。
Note that all other sessions will immediately be able to see the data once it has been successfully loaded. This violates the normal rules of MVCC visibility and users should be aware of the potential problems this might cause. データのロードに成功すると、他のすべてのセッションから即座にデータが参照可能になることに注意してください。 これはMVCC可視性に関する一般的な規則に違反しますので、ユーザはこれが引き起こすかもしれない潜在的な問題に注意しなければなりません。
DELIMITER
Specifies the character that separates columns within each row
(line) of the file. The default is a tab character in text format,
a comma in <literal>CSV</literal> format.
This must be a single one-byte character.
This option is not allowed when using <literal>binary</literal> format.
ファイルの各行内の列を区切る文字を指定します。
テキスト形式でのデフォルトはタブ文字、CSV形式ではカンマです。
これは単一の1バイト文字でなければなりません。
このオプションはbinary形式を使用する場合は許されません。
NULL
Specifies the string that represents a null value. The default is
<literal>\N</literal> (backslash-N) in text format, and an unquoted empty
string in <literal>CSV</literal> format. You might prefer an
empty string even in text format for cases where you don't want to
distinguish nulls from empty strings.
This option is not allowed when using <literal>binary</literal> format.
NULL値を表す文字列を指定します。
デフォルトは、テキスト形式では\N(バックスラッシュN)、CSV形式では引用符のない空文字です。
NULL値と空文字列を区別する必要がない場合は、テキスト形式であっても空文字列を使用した方が良いかもしれません。
このオプションはbinary形式を使用する場合は許されません。
When using <command>COPY FROM</command>, any data item that matches
this string will be stored as a null value, so you should make
sure that you use the same string as you used with
<command>COPY TO</command>.
COPY FROMの場合、この文字列と一致するデータ要素はNULL値として格納されます。
COPY TO実行時に使用した同じ文字列を使用するようにしてください。
DEFAULT
Specifies the string that represents a default value. Each time the string
is found in the input file, the default value of the corresponding column
will be used.
This option is allowed only in <command>COPY FROM</command>, and only when
not using <literal>binary</literal> format.
デフォルト値を表す文字列を指定します。
文字列が入力ファイルで見つかるたびに、対応する列のデフォルト値が使用されます。
このオプションは、COPY FROMでのみ使用でき、binary形式を使用しない場合にのみ使用できます。
HEADER
Specifies that the file contains a header line with the names of each
column in the file. On output, the first line contains the column
names from the table. On input, the first line is discarded when this
option is set to <literal>true</literal> (or equivalent Boolean value).
If this option is set to <literal>MATCH</literal>, the number and names
of the columns in the header line must match the actual column names of
the table, in order; otherwise an error is raised.
This option is not allowed when using <literal>binary</literal> format.
The <literal>MATCH</literal> option is only valid for <command>COPY
FROM</command> commands.
ファイルがファイル内の各列の名前を持つヘッダ行を含むことを指定します。
出力時には、最初の行にテーブルの列名が含まれます。
入力時には、このオプションがtrue(または同等の論理値)に設定されている場合、最初の行は破棄されます。
このオプションがMATCHに設定されている場合、ヘッダ行の列の番号と名前が、テーブルの実際の列名と順番に一致しなければなりません。一致しない場合は、エラーが発生します。
binary形式を使用している場合、このオプションは使用できません。
MATCHオプションはCOPY FROMコマンドでのみ有効です。
QUOTE
Specifies the quoting character to be used when a data value is quoted.
The default is double-quote.
This must be a single one-byte character.
This option is allowed only when using <literal>CSV</literal> format.
データ値を引用符付けする際に使用される引用符文字を指定します。
デフォルトは二重引用符です。
これは単一の1バイト文字でなければなりません。
このオプションはCSV形式を使用する場合にのみ許されます。
ESCAPE
Specifies the character that should appear before a
data character that matches the <literal>QUOTE</literal> value.
The default is the same as the <literal>QUOTE</literal> value (so that
the quoting character is doubled if it appears in the data).
This must be a single one-byte character.
This option is allowed only when using <literal>CSV</literal> format.
データ内の文字がQUOTEの値と一致する場合に、その前に現れなければならない文字を指定します。
デフォルトはQUOTEの値と同じです(このためデータ内に引用符用文字があるときは二つ続けます)。
これは単一の1バイト文字でなければなりません。
このオプションはCSV形式を使用する場合のみ許されます。
FORCE_QUOTE
Forces quoting to be
used for all non-<literal>NULL</literal> values in each specified column.
<literal>NULL</literal> output is never quoted. If <literal>*</literal> is specified,
non-<literal>NULL</literal> values will be quoted in all columns.
This option is allowed only in <command>COPY TO</command>, and only when
using <literal>CSV</literal> format.
指定された各列内にある全ての非NULL値を強制的に引用符で囲みます。
NULL出力は引用符で囲まれません。
*が指定された場合、非NULL値はすべての列で引用符付けされます。
このオプションはCOPY TOにおいて、かつ、CSV形式を使用する場合のみ許されます。
FORCE_NOT_NULL
Do not match the specified columns' values against the null string.
In the default case where the null string is empty, this means that
empty values will be read as zero-length strings rather than nulls,
even when they are not quoted.
If <literal>*</literal> is specified, the option will be applied to all columns.
This option is allowed only in <command>COPY FROM</command>, and only when
using <literal>CSV</literal> format.
指定された列の値をNULL文字列に対して比較しません。
NULL文字列が空であるデフォルトでは、空の値は引用符付けされていなくてもNULLではなく長さが0の文字列として読み取られることを意味します。
*が指定されている場合、このオプションはすべての列に適用されます。
このオプションはCOPY FROMで、かつ、CSV形式を使用する場合のみで許されます。
FORCE_NULL
Match the specified columns' values against the null string, even
if it has been quoted, and if a match is found set the value to
<literal>NULL</literal>. In the default case where the null string is empty,
this converts a quoted empty string into NULL.
If <literal>*</literal> is specified, the option will be applied to all columns.
This option is allowed only in <command>COPY FROM</command>, and only when
using <literal>CSV</literal> format.
指定された列の値を、それが引用符付きであったとしても、NULL文字列と比較し、一致した場合は値をNULLにセットします。
NULL文字列が空であるデフォルトでは、引用符付きの空文字列をNULLに変換します。
*が指定されている場合、このオプションはすべての列に適用されます。
このオプションはCOPY FROMで、かつCSV形式を使用する場合のみ許されます。
ON_ERROR
Specifies how to behave when encountering an error converting a column's
input value into its data type.
An <replaceable class="parameter">error_action</replaceable> value of
<literal>stop</literal> means fail the command, while
<literal>ignore</literal> means discard the input row and continue with the next one.
The default is <literal>stop</literal>.
列の入力値をデータ型に変換する際にエラーが発生した場合の動作を指定します。
error_actionの値がstopの場合、コマンドは失敗します。ignoreの場合、入力行は破棄され、次の行に移ります。
デフォルトはstopです。
The <literal>ignore</literal> option is applicable only for <command>COPY FROM</command>
when the <literal>FORMAT</literal> is <literal>text</literal> or <literal>csv</literal>.
ignoreオプションは、FORMATがtextまたはcsvの場合のCOPY FROMにのみ適用できます。
A <literal>NOTICE</literal> message containing the ignored row count is
emitted at the end of the <command>COPY FROM</command> if at least one
row was discarded. When <literal>LOG_VERBOSITY</literal> option is set to
<literal>verbose</literal>, a <literal>NOTICE</literal> message
containing the line of the input file and the column name whose input
conversion has failed is emitted for each discarded row.
When it is set to <literal>silent</literal>, no message is emitted
regarding ignored rows.
《マッチ度[74.497992]》少なくとも1行が破棄された場合、COPY FROMの最後に、無視された行数を含むNOTICEメッセージが出力されます。
LOG_VERBOSITYオプションがverboseに設定されている場合、破棄された各行に対して、入力ファイルの行と入力変換に失敗した列名を含むNOTICEメッセージが出力されます。
《機械翻訳》NOTICE無視されたメッセージカウントを含む行は、COPY FROM少なくとも1つの行が破棄された場合の最後にエミットされます。
LOG_VERBOSITYオプションがverboseに設定されている場合、NOTICE入力されたファイルの直線と、入力された変換が失敗したカラム名前を含む行は、破棄されたごとにエミットされます。
silentに設定されている場合、無視された行に関してメッセージはエミットされません。
メッセージ
REJECT_LIMIT
Specifies the maximum number of errors tolerated while converting a
column's input value to its data type, when <literal>ON_ERROR</literal> is
set to <literal>ignore</literal>.
If the input causes more errors than the specified value, the <command>COPY</command>
command fails, even with <literal>ON_ERROR</literal> set to <literal>ignore</literal>.
This clause must be used with <literal>ON_ERROR</literal>=<literal>ignore</literal>
and <replaceable class="parameter">maxerror</replaceable> must be positive <type>bigint</type>.
If not specified, <literal>ON_ERROR</literal>=<literal>ignore</literal>
allows an unlimited number of errors, meaning <command>COPY</command> will
skip all erroneous data.
《機械翻訳》ON_ERRORがignoreに設定されている場合、カラムの入力値をデータタイプに変換するときに許容されるエラーの最大数を指定します。
入力が指定された値よりも多くのエラーを引き起こした場合、COPYコマンドはON_ERRORに設定されている場合でも失敗します。
ignoreこの句はON_ERROR=ignoreおよびmaxerrorは正のbigintである必要があります。
指定されていない場合、ON_ERROR=ignoreはエラーの数に制限がないため、COPYはエラーのあるすべてのデータをスキップします。
ENCODING
Specifies that the file is encoded in the <replaceable
class="parameter">encoding_name</replaceable>. If this option is
omitted, the current client encoding is used. See the Notes below
for more details.
ファイルがencoding_nameで符号化されていることを指定します。
このオプションが省略された場合、現在のクライアント符号化方式が使用されます。
後述の注釈を参照してください。
LOG_VERBOSITY
Specifies the amount of messages emitted by a <command>COPY</command>
command: <literal>default</literal>, <literal>verbose</literal>, or
<literal>silent</literal>.
If <literal>verbose</literal> is specified, additional messages are
emitted during processing.
<literal>silent</literal> suppresses both verbose and default messages.
《マッチ度[61.631420]》COPYコマンドが出力するメッセージの量を指定します。
defaultまたはverboseです。
verboseが指定された場合、処理中に追加のメッセージが出力されます。
《機械翻訳》COPYコマンド:default、verboseまたはsilent。
verboseが指定されている場合は、処理中に追加のメッセージが発行されます。
silent VERBOSEとデフォルトの両方のメッセージが抑制されます。
This is currently used in <command>COPY FROM</command> command when
<literal>ON_ERROR</literal> option is set to <literal>ignore</literal>.
これは現在、ON_ERRORオプションがignoreに設定されている場合にCOPY FROMコマンドで使用されます。
WHERE
The optional <literal>WHERE</literal> clause has the general form
省略可能なWHERE句の一般的な形は以下の通りです。
WHERE condition
where <replaceable class="parameter">condition</replaceable> is
any expression that evaluates to a result of type
<type>boolean</type>. Any row that does not satisfy this
condition will not be inserted to the table. A row satisfies the
condition if it returns true when the actual row values are
substituted for any variable references.
ここでconditionは、評価の結果がboolean型になる任意の式です。
この条件を満たさない行はテーブルに挿入されません。
変数参照を実際の行の値で置き換えた時に真を返す場合に、行は条件を満たします。
Currently, subqueries are not allowed in <literal>WHERE</literal>
expressions, and the evaluation does not see any changes made by the
<command>COPY</command> itself (this matters when the expression
contains calls to <literal>VOLATILE</literal> functions).
今のところ、WHERE式の中での副問い合わせは認められていませんし、評価はCOPY自身により行われた変更を見ることはありません(これは、式がVOLATILE関数の呼び出しを含む場合に問題になります)。
On successful completion, a <command>COPY</command> command returns a command
tag of the form
正常に完了した場合、COPYコマンドは以下の形式のコマンドタグを返します。
COPY count
The <replaceable class="parameter">count</replaceable> is the number
of rows copied.
countはコピーされた行数です。
<application>psql</application> will print this command tag only if the command
was not <literal>COPY ... TO STDOUT</literal>, or the
equivalent <application>psql</application> meta-command
<literal>\copy ... to stdout</literal>. This is to prevent confusing the
command tag with the data that was just printed.
psqlはコマンドがCOPY ... TO STDOUTであった場合、および、それと同等なpsqlのメタコマンド\copy ... to stdoutであった場合は、このコマンドタグを表示しません。
これは、コマンドタグが表示されたデータと混同されないようにするためです。
<command>COPY TO</command> can be used with plain
tables and populated materialized views.
For example,
<literal>COPY <replaceable class="parameter">table</replaceable>
TO</literal> copies the same rows as
<literal>SELECT * FROM ONLY <replaceable class="parameter">table</replaceable></literal>.
However it doesn't directly support other relation types,
such as partitioned tables, inheritance child tables, or views.
To copy all rows from such relations, use <literal>COPY (SELECT * FROM
<replaceable class="parameter">table</replaceable>) TO</literal>.
《機械翻訳》COPY TOプレーン・テーブルと移入されたマテリアライズド・ビューで使用できます。
例の場合、COPY はtable TOSELECT * FROM ONLY と同じ行をコピーします。
ただし、テーブルパーティション、継承の子テーブル、またはビューなど、他のリレーションタイプを直接サポートすることはありません。
このようなリレーションからすべての行をコピーするには、tableCOPY (SELECT * FROM を使用します。
table) TO
<command>COPY FROM</command> can be used with plain, foreign, or
partitioned tables or with views that have
<literal>INSTEAD OF INSERT</literal> triggers.
COPY FROMは通常のテーブル、外部テーブル、パーティションテーブルおよびINSTEAD OF INSERTトリガを持つビューに対して使用することができます。
You must have select privilege on the table
whose values are read by <command>COPY TO</command>, and
insert privilege on the table into which values
are inserted by <command>COPY FROM</command>. It is sufficient
to have column privileges on the column(s) listed in the command.
COPY TOの場合は値を読み込むテーブルに対するSELECT権限が、COPY FROMの場合は値を挿入するテーブルに対するINSERT権限が必要です。
コマンド内で列挙された列に対する列権限があれば十分です。
If row-level security is enabled for the table, the relevant
<command>SELECT</command> policies will apply to <literal>COPY
<replaceable class="parameter">table</replaceable> TO</literal> statements.
Currently, <command>COPY FROM</command> is not supported for tables
with row-level security. Use equivalent <command>INSERT</command>
statements instead.
テーブルの行単位セキュリティが有効な場合、適切なSELECTポリシーがCOPY 文に適用されます。
現在のところ、table TOCOPY FROMは行単位セキュリティが有効なテーブルに対してはサポートされません。
代わりにそれと等価なINSERTを使ってください。
Files named in a <command>COPY</command> command are read or written
directly by the server, not by the client application. Therefore,
they must reside on or be accessible to the database server machine,
not the client. They must be accessible to and readable or writable
by the <productname>PostgreSQL</productname> user (the user ID the
server runs as), not the client. Similarly,
the command specified with <literal>PROGRAM</literal> is executed directly
by the server, not by the client application, must be executable by the
<productname>PostgreSQL</productname> user.
<command>COPY</command> naming a file or command is only allowed to
database superusers or users who are granted one of the roles
<literal>pg_read_server_files</literal>,
<literal>pg_write_server_files</literal>,
or <literal>pg_execute_server_program</literal>, since it allows reading
or writing any file or running a program that the server has privileges to
access.
COPYコマンドで指定するファイルは、クライアントアプリケーションではなく、サーバが直接読み込み/書き込みを行います。
したがって、それらのファイルは、クライアントではなく、データベースサーバマシン上に存在するか、または、データベースサーバマシンからアクセス可能である必要があります。
さらに、クライアントではなく、PostgreSQLユーザ(サーバを実行しているユーザID)が、アクセス権限と読み書き権限を持っている必要があります。
同様に、PROGRAMで指定されたコマンドは、クライアントアプリケーションではなくサーバにより直接実行されるため、PostgreSQLユーザによって実行可能でなければなりません。
ファイル名またはコマンドを指定したCOPYの実行は、データベースのスーパーユーザとロールpg_read_server_files、pg_write_server_files、pg_execute_server_programの内の1つの権限を許可されたユーザのみに許可されています。このコマンドによって、サーバがアクセス権限を持つ全てのファイルの読み込み、書き込みやプログラムの実行が可能になってしまうためです。
Do not confuse <command>COPY</command> with the
<application>psql</application> instruction
<command><link linkend="app-psql-meta-commands-copy">\copy</link></command>. <command>\copy</command> invokes
<command>COPY FROM STDIN</command> or <command>COPY TO
STDOUT</command>, and then fetches/stores the data in a file
accessible to the <application>psql</application> client. Thus,
file accessibility and access rights depend on the client rather
than the server when <command>\copy</command> is used.
COPYをpsqlの\copyと混同しないでください。
\copyはCOPY FROM STDINやCOPY TO STDOUTを呼び出し、psqlクライアントからアクセスできるファイルにデータの書き込み/読み込みを行います。
したがって、\copyコマンドでは、ファイルへのアクセスが可能かどうかと、ファイルに対するアクセス権限の有無は、サーバではなくクライアント側に依存します。
It is recommended that the file name used in <command>COPY</command>
always be specified as an absolute path. This is enforced by the
server in the case of <command>COPY TO</command>, but for
<command>COPY FROM</command> you do have the option of reading from
a file specified by a relative path. The path will be interpreted
relative to the working directory of the server process (normally
the cluster's data directory), not the client's working directory.
COPYでファイル名を指定する時は、常に絶対パスで記述することをお勧めします。
COPY TOコマンドの場合はサーバによって絶対パス指定に変更させられますが、COPY FROMコマンドでは相対パスで指定されたファイルを読み込むことも可能となっています。
後者では、クライアントの作業ディレクトリではなく、サーバプロセスの作業ディレクトリ(通常はクラスタのデータディレクトリ)からの相対的なディレクトリとして解釈されます。
Executing a command with <literal>PROGRAM</literal> might be restricted
by the operating system's access control mechanisms, such as SELinux.
PROGRAMを用いたコマンド実行は、SELinuxなどのオペレーティングシステムのアクセス制御機構によって制限されるかもしれません。
<command>COPY FROM</command> will invoke any triggers and check
constraints on the destination table. However, it will not invoke rules.
COPY FROMは、宛先テーブル上で任意のトリガと検査制約を呼び出します。
ただし、ルールは呼び出しません。
For identity columns, the <command>COPY FROM</command> command will always
write the column values provided in the input data, like
the <command>INSERT</command> option <literal>OVERRIDING SYSTEM
VALUE</literal>.
識別列については、COPY FROMコマンドはINSERTのオプションOVERRIDING SYSTEM VALUEと同じように、必ず入力データが提供した列の値を書き込みます。
<command>COPY</command> input and output is affected by
<varname>DateStyle</varname>. To ensure portability to other
<productname>PostgreSQL</productname> installations that might use
non-default <varname>DateStyle</varname> settings,
<varname>DateStyle</varname> should be set to <literal>ISO</literal> before
using <command>COPY TO</command>. It is also a good idea to avoid dumping
data with <varname>IntervalStyle</varname> set to
<literal>sql_standard</literal>, because negative interval values might be
misinterpreted by a server that has a different setting for
<varname>IntervalStyle</varname>.
COPYの入出力はDateStyleの影響を受けます。
デフォルト以外のDateStyleが設定された可能性があるPostgreSQLインストレーションとの移植を確実に行いたい場合は、COPYを使う前にDateStyleをISOに設定しなければなりません。
また、IntervalStyleをsql_standardとしてデータをダンプすることは避けることを勧めます。
負の時間間隔値が別のIntervalStyle設定を持つサーバで誤解釈される可能性があるためです。
Input data is interpreted according to <literal>ENCODING</literal>
option or the current client encoding, and output data is encoded
in <literal>ENCODING</literal> or the current client encoding, even
if the data does not pass through the client but is read from or
written to a file directly by the server.
たとえデータがクライアント経由ではなくサーバにより直接ファイルから読み書きされるとしても、入力データはENCODINGオプションまたは現在のクライアント符号化方式にしたがって解釈され、出力データはENCODINGオプションまたは現在のクライアント符号化方式で符号化されます。
The <command>COPY FROM</command> command physically inserts input rows
into the table as it progresses. If the command fails, these rows are
left in a deleted state; these rows will not be visible, but still
occupy disk space. This might amount to considerable
wasted disk space if the failure happened well into a large copy
operation. <command>VACUUM</command> should be used to recover the
wasted space.
COPY FROMコマンドは、処理の進行中に入力行を物理的にテーブルに挿入します。
コマンドが失敗した場合、これらの行は削除された状態のままになります。
これらの行は表示されませんが、ディスク領域を占有します。
これは、大規模なコピー操作の途中で失敗した場合、かなりのディスク領域を浪費することになるかもしれません。
浪費された領域を回復するにはVACUUMを使用してください。
<literal>FORCE_NULL</literal> and <literal>FORCE_NOT_NULL</literal> can be used
simultaneously on the same column. This results in converting quoted
null strings to null values and unquoted null strings to empty strings.
FORCE_NULLとFORCE_NOT_NULLは同じ列について同時に使うことができます。
その場合の結果は、引用符付きのNULL文字列をNULL値に変換し、引用符なしのNULL文字列を空文字列に変換します。
When the <literal>text</literal> format is used,
the data read or written is a text file with one line per table row.
Columns in a row are separated by the delimiter character.
The column values themselves are strings generated by the
output function, or acceptable to the input function, of each
attribute's data type. The specified null string is used in
place of columns that are null.
<command>COPY FROM</command> will raise an error if any line of the
input file contains more or fewer columns than are expected.
text形式を使用する場合、読み書きされるデータはテーブルの1つの行を1行で表したテキストファイルとなります。
行内の列は区切り文字で区切られます。
列の値自体は、その属性のデータ型の出力関数で生成された、または、その入力関数で受け付け可能な文字列です。
値がNULLの列では、代わりに指定されたNULL値を表す文字列が使用されます。
入力ファイルのいずれかの行にある列数が予期された数と違う場合、COPY FROMはエラーを発生します。
End of data can be represented by a line containing just
backslash-period (<literal>\.</literal>). An end-of-data marker is
not necessary when reading from a file, since the end of file
serves perfectly well; in that context this provision exists only for
backward compatibility. However, <application>psql</application>
uses <literal>\.</literal> to terminate a <literal>COPY FROM
STDIN</literal> operation (that is, reading
in-line <command>COPY</command> data in an SQL script). In that
context the rule is needed to be able to end the operation before the
end of the script.
《機械翻訳》データの終わりは、バックスラッシュ-ピリオド\.のみを含む行で表すことができます。
データの終わりは完全に機能するため、ファイルから読み取る場合はファイルの終わりマーカーは必要ありません。
コンテキストでは、この規定は逆方向互換性に対してのみ存在します。
ただし、psqlでは、\.を使用してCOPY FROM STDINオペレーションを終了します。
つまり、SQLスクリプトでは-直線COPYデータを読み取ります。
そのコンテキストでは、ルールはオペレーション前をスクリプトの終わりで終了できる必要があります。
Backslash characters (<literal>\</literal>) can be used in the
<command>COPY</command> data to quote data characters that might
otherwise be taken as row or column delimiters. In particular, the
following characters <emphasis>must</emphasis> be preceded by a backslash if
they appear as part of a column value: backslash itself,
newline, carriage return, and the current delimiter character.
バックスラッシュ文字(\)は、COPY対象データ内で、行や列の区切り文字と判定される可能性があるデータ文字列の引用符付けに使用します。
特に、バックスラッシュ自体、改行、復帰、使用中の区切り文字などの文字が列の値に含まれている場合は、必ず前にバックスラッシュを付けなければなりません。
The specified null string is sent by <command>COPY TO</command> without
adding any backslashes; conversely, <command>COPY FROM</command> matches
the input against the null string before removing backslashes. Therefore,
a null string such as <literal>\N</literal> cannot be confused with
the actual data value <literal>\N</literal> (which would be represented
as <literal>\\N</literal>).
指定されたNULL文字列はバックスラッシュを付けずにCOPY TOに送られます。
一方、COPY FROMでは、バックスラッシュを削除する前にNULL文字列と入力を比較します。
したがって、\NといったNULL文字列が実際の\Nというデータ値と混乱することはあり得ません。
(これは\\Nとして表現されます。)
The following special backslash sequences are recognized by
<command>COPY FROM</command>:
COPY FROMは、バックスラッシュで始まる次のような文字の並びを識別します。
| 文字の並び | 表現 |
|---|---|
\b | バックスペース(ASCII 8) |
\f | 改ページ(ASCII 12) |
\n | 改行(ASCII 10) |
\r | 復帰(ASCII 13) |
\t | タブ(ASCII 9) |
\v | 垂直タブ(ASCII 11) |
\数字 | バックスラッシュに続き1から3個の8進数の数字をコード番号として指定すると、そのコード番号が表すバイトを指定できます。 |
\x数字 | バックスラッシュ、xという並びに続き1から2個の16進数の数字を指定すると、そのコード番号が表すバイトを指定できます。 |
Presently, <command>COPY TO</command> will never emit an octal or
hex-digits backslash sequence, but it does use the other sequences
listed above for those control characters.
現在、COPY TOは、バックスラッシュの後ろに8進数や16進数を付けた形式で文字を出力することはありませんが、上記一覧にある制御文字については、バックスラッシュの文字並びを使用します。
Any other backslashed character that is not mentioned in the above table
will be taken to represent itself. However, beware of adding backslashes
unnecessarily, since that might accidentally produce a string matching the
end-of-data marker (<literal>\.</literal>) or the null string (<literal>\N</literal> by
default). These strings will be recognized before any other backslash
processing is done.
上表で記載されていないバックスラッシュ付きの文字はすべて、その文字自体として解釈されます。
しかし、不要なバックスラッシュの追加には注意してください。
偶然にデータの終わりを示す印(\.)やヌル文字列(デフォルトでは\N)と合致する文字列を生成してしまうかもしれないためです。
これらの文字列は他のバックスラッシュの処理を行う前に解釈されます。
It is strongly recommended that applications generating <command>COPY</command> data convert
data newlines and carriage returns to the <literal>\n</literal> and
<literal>\r</literal> sequences respectively. At present it is
possible to represent a data carriage return by a backslash and carriage
return, and to represent a data newline by a backslash and newline.
However, these representations might not be accepted in future releases.
They are also highly vulnerable to corruption if the <command>COPY</command> file is
transferred across different machines (for example, from Unix to Windows
or vice versa).
COPYデータを生成するアプリケーションは、データ内の改行と復帰をそれぞれ、\nと\rに変換することを強く推奨されています。
現在のところ、バックスラッシュと復帰文字でデータ内の復帰を表したり、バックスラッシュと改行文字でデータ内の改行を表すことが可能です。
しかし、こういった表現は今後のリリースでは、受け付けられなくなる可能性があります。
また、COPYファイルが異なるマシンをまたがって転送される場合、破損するおそれがかなりあります
(例えば、UnixからWindowsあるいはその逆)。
All backslash sequences are interpreted after encoding conversion. The bytes specified with the octal and hex-digit backslash sequences must form valid characters in the database encoding. バックスラッシュで始まる文字の並びはすべて符号化方式変換の後で解釈されます。 バックスラッシュの後ろに8進数や16進数を付けた形式で指定されたバイトはデータベース符号化方式において有効な文字でなければなりません。
<command>COPY TO</command> will terminate each row with a Unix-style
newline (<quote><literal>\n</literal></quote>). Servers running on Microsoft Windows instead
output carriage return/newline (<quote><literal>\r\n</literal></quote>), but only for
<command>COPY</command> to a server file; for consistency across platforms,
<command>COPY TO STDOUT</command> always sends <quote><literal>\n</literal></quote>
regardless of server platform.
<command>COPY FROM</command> can handle lines ending with newlines,
carriage returns, or carriage return/newlines. To reduce the risk of
error due to un-backslashed newlines or carriage returns that were
meant as data, <command>COPY FROM</command> will complain if the line
endings in the input are not all alike.
COPY TOは各行の行末にUnix形式の改行(「\n」)を出力します。
なお、Microsoft Windowsで稼働するサーバの場合は、サーバ上のファイルへのCOPYの場合にのみ復帰/改行(「\r\n」)を出力します。
プラットフォームをまたがる一貫性のために、サーバのプラットフォームにかかわらず、COPY TO STDOUTは常に「\n」を送信します。
COPY FROMは、改行、復帰、復帰/改行を行末として扱うことができます。
データを意図したバックスラッシュのない改行や復帰によるエラーの危険性を減らすために、COPY FROMは、入力行の行末が全て共通でない場合に警告を発します。
This format option is used for importing and exporting the Comma-
Separated Value (<literal>CSV</literal>) file format used by many other
programs, such as spreadsheets. Instead of the escaping rules used by
<productname>PostgreSQL</productname>'s standard text format, it
produces and recognizes the common <literal>CSV</literal> escaping mechanism.
《マッチ度[94.285714]》この形式オプションは、スプレッドシートなど他の多くのプログラムで使用されるカンマ区切り値(CSV)ファイル形式をインポート、エクスポートするために使用されます。
PostgreSQLの標準テキスト形式で使用されるエスケープ規則の代わりに、一般的なCSVのエスケープ機構を生成、認識します。
The values in each record are separated by the <literal>DELIMITER</literal>
character. If the value contains the delimiter character, the
<literal>QUOTE</literal> character, the <literal>NULL</literal> string, a carriage
return, or line feed character, then the whole value is prefixed and
suffixed by the <literal>QUOTE</literal> character, and any occurrence
within the value of a <literal>QUOTE</literal> character or the
<literal>ESCAPE</literal> character is preceded by the escape character.
You can also use <literal>FORCE_QUOTE</literal> to force quotes when outputting
non-<literal>NULL</literal> values in specific columns.
各レコードの値はDELIMITER文字で区切られます。
区切り文字、QUOTE文字、NULL文字列、復帰、改行文字を含む値の場合、全体の値の前後にQUOTE文字が付与されます。値の中でQUOTE文字やESCAPE文字が現れる場合、その前にエスケープ用の文字が付与されます。
また、FORCE_QUOTEを使用して、特定列内の非NULL値を出力する時に強制的に引用符を付与することもできます。
The <literal>CSV</literal> format has no standard way to distinguish a
<literal>NULL</literal> value from an empty string.
<productname>PostgreSQL</productname>'s <command>COPY</command> handles this by quoting.
A <literal>NULL</literal> is output as the <literal>NULL</literal> parameter string
and is not quoted, while a non-<literal>NULL</literal> value matching the
<literal>NULL</literal> parameter string is quoted. For example, with the
default settings, a <literal>NULL</literal> is written as an unquoted empty
string, while an empty string data value is written with double quotes
(<literal>""</literal>). Reading values follows similar rules. You can
use <literal>FORCE_NOT_NULL</literal> to prevent <literal>NULL</literal> input
comparisons for specific columns. You can also use
<literal>FORCE_NULL</literal> to convert quoted null string data values to
<literal>NULL</literal>.
CSV形式にはNULL値と空文字列とを区別する標準的な方法はありません。
PostgreSQLのCOPYでは引用符によってこれを区別しています。
NULLはNULLパラメータの文字列として出力され、引用符で囲まれません。
一方、NULLパラメータの文字列に一致する非NULL値は引用符で囲まれます。
たとえばデフォルトの設定では、NULLは引用符付けのない空文字列として出力され、空文字列のデータ値は2つの引用符("")で出力されます。
データの読み込みの際も同様の規則に従います。
FORCE_NOT_NULLを使用して、特定列に対しNULL入力の比較を行わないようにすることもできます。
またFORCE_NULLを使うことで、引用符付きのNULL文字列のデータの値をNULLに変換することもできます。
Because backslash is not a special character in the <literal>CSV</literal>
format, the end-of-data marker used in text mode (<literal>\.</literal>)
is not normally treated as special when reading <literal>CSV</literal>
data. An exception is that <application>psql</application> will terminate
a <literal>COPY FROM STDIN</literal> operation (that is, reading
in-line <command>COPY</command> data in an SQL script) at a line containing
only <literal>\.</literal>, whether it is text or <literal>CSV</literal>
mode.
《機械翻訳》バックスラッシュはCSVフォーマットの特殊文字ではないため、データ\.で使用されるテキストモード終了マーカーは、通常、CSVデータを読み取る際には特殊文字として扱われません。
例外は、psqlはCOPY FROM STDINオペレーションを終了します(つまり、-直線COPYSQLスクリプトのデータを読み取ると、テキストであってもCSVモードであっても\.のみを含む行で終了します。
<productname>PostgreSQL</productname> versions before v18 always
recognized unquoted <literal>\.</literal> as an end-of-data marker,
even when reading from a separate file. For compatibility with older
versions, <command>COPY TO</command> will quote <literal>\.</literal>
when it's alone on a line, even though this is no longer necessary.
《機械翻訳》PostgreSQL前v18のバージョンでは、別のデータから読み込んだ場合でも、常にクォートされていない\.ファイルの終わりのマーカーとしてを認識していました。
古いバージョンの互換性では、COPY TOは1行に引用符\.がある場合、これが不要になったとしても引用符で囲みます。
In <literal>CSV</literal> format, all characters are significant. A quoted value
surrounded by white space, or any characters other than
<literal>DELIMITER</literal>, will include those characters. This can cause
errors if you import data from a system that pads <literal>CSV</literal>
lines with white space out to some fixed width. If such a situation
arises you might need to preprocess the <literal>CSV</literal> file to remove
the trailing white space, before importing the data into
<productname>PostgreSQL</productname>.
CSV形式では文字はすべて意味を持ちます。
空白文字で括られた引用符付きの値などDELIMITER以外のすべての文字がこうした文字に含まれます。
これにより、固定長にするためにCSVの行に空白文字を埋めるシステムから取り出したデータをインポートする時にエラーが発生する可能性があります。
このような状況になった場合、PostgreSQLにデータをインポートする前に、そのCSVファイルから余分な空白を除去する前処理が必要になります。
<literal>CSV</literal> format will both recognize and produce <literal>CSV</literal> files with quoted
values containing embedded carriage returns and line feeds. Thus
the files are not strictly one line per table row like text-format
files.
CSV形式は、復帰文字や改行文字が埋め込まれ引用符で囲まれた値を含むCSVファイルを認識し、生成します。
したがって、このファイルでは、テキスト形式とは異なり、1つのテーブル行が1行で表されているとは限りません。
Many programs produce strange and occasionally perverse <literal>CSV</literal> files,
so the file format is more a convention than a standard. Thus you
might encounter some files that cannot be imported using this
mechanism, and <command>COPY</command> might produce files that other
programs cannot process.
奇妙な(時には間違った)CSVファイルを生成するプログラムは多く存在するので、このファイル形式は標準というよりも慣習と言えるものです。
したがって、この機能でインポートできないファイルが存在するかもしれませんし、COPYが他のプログラムで処理できないファイルを生成するかもしれません。
The <literal>binary</literal> format option causes all data to be
stored/read as binary format rather than as text. It is
somewhat faster than the text and <literal>CSV</literal> formats,
but a binary-format file is less portable across machine architectures and
<productname>PostgreSQL</productname> versions.
Also, the binary format is very data type specific; for example
it will not work to output binary data from a <type>smallint</type> column
and read it into an <type>integer</type> column, even though that would work
fine in text format.
binary形式オプションにより、すべてのデータはテキストではなくバイナリ形式で書き込み/読み取りされるようになります。
テキストやCSV形式よりも多少高速になりますが、バイナリ形式のファイルはマシンアーキテクチャやPostgreSQLのバージョンをまたがる移植性が落ちます。
またバイナリ形式はデータ型に非常に依存します。
たとえば、smallint列からバイナリデータを出力し、それをinteger列として読み込むことはできません。同じことをテキスト形式で実行すれば動作するのですが。
The <literal>binary</literal> file format consists
of a file header, zero or more tuples containing the row data, and
a file trailer. Headers and data are in network byte order.
binaryファイルの形式は、ファイルヘッダ、行データを含む0以上のタプル、ファイルトレーラから構成されます。
ヘッダとデータはネットワークバイトオーダーです。
<productname>PostgreSQL</productname> releases before 7.4 used a different binary file format. 7.4以前のリリースのPostgreSQLでは異なるバイナリファイル形式を使用していました。
The file header consists of 15 bytes of fixed fields, followed by a variable-length header extension area. The fixed fields are: ファイルヘッダは15バイトの固定フィールドとその後に続く可変長ヘッダ拡張領域から構成されます。 固定フィールドは以下の通りです。
11-byte sequence <literal>PGCOPY\n\377\r\n\0</literal> — note that the zero byte
is a required part of the signature. (The signature is designed to allow
easy identification of files that have been munged by a non-8-bit-clean
transfer. This signature will be changed by end-of-line-translation
filters, dropped zero bytes, dropped high bits, or parity changes.)
PGCOPY\n\377\r\n\0という11バイトの並びです。
この署名の必須部分にNULLバイトが含まれていることに注意してください
(この署名は、8ビットを通過させない転送方式によってファイルが破損した場合、これを容易に識別できるように設計されています。
署名は、改行コード変換やNULLバイトの削除、上位ビット落ち、パリティの変更などによって変化します)。
32-bit integer bit mask to denote important aspects of the file format. Bits are numbered from 0 (<acronym>LSB</acronym>) to 31 (<acronym>MSB</acronym>). Note that this field is stored in network byte order (most significant byte first), as are all the integer fields used in the file format. Bits 16–31 are reserved to denote critical file format issues; a reader should abort if it finds an unexpected bit set in this range. Bits 0–15 are reserved to signal backwards-compatible format issues; a reader should simply ignore any unexpected bits set in this range. Currently only one flag bit is defined, and the rest must be zero: このファイル形式の重要な部分となる32ビット整数のビットマスクです。 ビットには0(LSB) から31(MSB)までの番号が付いています。 このフィールドは、このファイル形式で使用される他の全ての整数フィールドも同様、ネットワークバイトオーダー(最上位バイトが最初に現れる)で保存されていることに注意してください。 ファイル形式上の致命的な問題を表すために、16–31ビットは予約されています。 この範囲に想定外のビットが設定されていることが判明した場合、読み込み先は処理を中断しなければなりません。 後方互換における形式の問題を通知するために、0–15ビットは予約されています。 この範囲に想定外のビットが設定されていても、読み込み先は無視すべきです。 現在、1つのビットだけがフラグビットとして定義されており、残りは0でなければなりません。
If 1, OIDs are included in the data; if 0, not. Oid system columns are not supported in <productname>PostgreSQL</productname> anymore, but the format still contains the indicator. 1ならば、OIDがデータに含まれています。0ならば、含まれていません。 OIDシステム列は今はもうPostgreSQLでサポートされていませんが、フォーマットには指標が含まれています。
32-bit integer, length in bytes of remainder of header, not including self. Currently, this is zero, and the first tuple follows immediately. Future changes to the format might allow additional data to be present in the header. A reader should silently skip over any header extension data it does not know what to do with. 自分自身を除いた、ヘッダの残り部分のバイト長を示す32ビットの整数です。 現在、これは0となっており、すぐ後に最初のタプルが続きます。 今後、ヘッダ内に追加データを格納するような形式の変更があるかもしれません。 読み込み側では、ヘッダ拡張データの扱いがわからない場合、そのデータをスキップしなければなりません。
The header extension area is envisioned to contain a sequence of self-identifying chunks. The flags field is not intended to tell readers what is in the extension area. Specific design of header extension contents is left for a later release. ヘッダ拡張領域は、それ自身で認識することができる塊の並びを保持するために用意されています。 フラグフィールドは読み込み先に拡張領域の内容を知らせるものではありません。 ヘッダ拡張内容の個々の設計は今後のリリースのために残してあります。
This design allows for both backwards-compatible header additions (add header extension chunks, or set low-order flag bits) and non-backwards-compatible changes (set high-order flag bits to signal such changes, and add supporting data to the extension area if needed). この設計によって、後方互換性を維持するヘッダの追加(ヘッダ拡張チャンクの追加や下位フラグビットの設定)と後方互換性のない変更(変更を通知するための高位フラグビットの設定や必要に応じた拡張領域へのサポート情報追加)の両方に対応できます。
Each tuple begins with a 16-bit integer count of the number of fields in the tuple. (Presently, all tuples in a table will have the same count, but that might not always be true.) Then, repeated for each field in the tuple, there is a 32-bit length word followed by that many bytes of field data. (The length word does not include itself, and can be zero.) As a special case, -1 indicates a NULL field value. No value bytes follow in the NULL case. 全てのタプルはタプル内のフィールド数を表す16ビットの整数から始まります(現時点では、テーブル内の全てのタプルは同一のフィールド数を持つことになっていますが、今後、これは変更される可能性があります)。 その後に、タプル中のそれぞれのフィールドが続きます。これらのフィールドには、先頭にフィールドデータが何バイトあるかを表す32ビット長のワードが付けられています。 (このワードが表す長さには自分自身は含まれません。したがって、0になることもあります。) 特殊な値としてNULLフィールドを表す-1が用意されています。 このNULLが指定された場合、値用のバイトはありません。
There is no alignment padding or any other extra data between fields. フィールド間には整列用のパッドやその他の余計なデータはありません。
Presently, all data values in a binary-format file are assumed to be in binary format (format code one). It is anticipated that a future extension might add a header field that allows per-column format codes to be specified. 現在、バイナリ形式のファイル内の全てのデータ値は、バイナリ形式(形式コード1)であると想定されています。 将来の拡張によって、列単位に形式コードを指定するヘッダフィールドが追加される可能性があります。
To determine the appropriate binary format for the actual tuple data you
should consult the <productname>PostgreSQL</productname> source, in
particular the <function>*send</function> and <function>*recv</function> functions for
each column's data type (typically these functions are found in the
<filename>src/backend/utils/adt/</filename> directory of the source
distribution).
実際のタプルデータとして適切なバイナリ形式を決定するためには、PostgreSQLのソース、特に各列のデータ型用の*send 関数と*recv関数(通常はソースの配布物内のsrc/backend/utils/adtディレクトリにあります)を調べなければなりません。
If OIDs are included in the file, the OID field immediately follows the field-count word. It is a normal field except that it's not included in the field-count. Note that oid system columns are not supported in current versions of <productname>PostgreSQL</productname>. このファイルにOIDが含まれる場合、OIDフィールドがフィールド数ワードの直後に続きます。 これは、フィールド数に含まれない点を除いて、通常のフィールドです。 OIDシステム列はPostgreSQLの現在のバージョンではサポートされていないことに注意してください。
The file trailer consists of a 16-bit integer word containing -1. This is easily distinguished from a tuple's field-count word. ファイルトレーラは、16ビットの整数ワードで構成され、-1が入っています。 タプルのフィールド数ワードとは、容易に区別できます。
A reader should report an error if a field-count word is neither -1 nor the expected number of columns. This provides an extra check against somehow getting out of sync with the data. 読み込み側は、フィールドカウントワードが-1でも、想定した列数でもなかった場合はエラーを報告しなければなりません。 これにより、何らかの理由でデータと一致しなかったことを判定する特別な検査を行うことが可能になります。
The following example copies a table to the client
using the vertical bar (<literal>|</literal>) as the field delimiter:
次の例では、フィールド区切り文字として縦棒(|)を使用してテーブルをクライアントにコピーします。
COPY country TO STDOUT (DELIMITER '|');
To copy data from a file into the <literal>country</literal> table:
ファイルからcountryテーブルにデータをコピーします。
COPY country FROM '/usr1/proj/bray/sql/country_data';
To copy into a file just the countries whose names start with 'A': 名前が'A'から始まる国のみをファイルにコピーします。
COPY (SELECT * FROM country WHERE country_name LIKE 'A%') TO '/usr1/proj/bray/sql/a_list_countries.copy';
To copy into a compressed file, you can pipe the output through an external compression program: 圧縮したファイルにコピーするためには、以下のように出力を外部の圧縮プログラムにパイプで渡すことができます。
COPY country TO PROGRAM 'gzip > /usr1/proj/bray/sql/country_data.gz';
Here is a sample of data suitable for copying into a table from
<literal>STDIN</literal>:
これはSTDINからテーブルにコピーするのに適したデータの例です。
AF AFGHANISTAN AL ALBANIA DZ ALGERIA ZM ZAMBIA ZW ZIMBABWE
Note that the white space on each line is actually a tab character. 各行の空白文字は実際にはタブ文字であることに注意してください。
The following is the same data, output in binary format.
The data is shown after filtering through the
Unix utility <command>od -c</command>. The table has three columns;
the first has type <type>char(2)</type>, the second has type <type>text</type>,
and the third has type <type>integer</type>. All the rows have a null value
in the third column.
以下は同一のデータをバイナリ形式で出力したものです。
データをUnixユーティリティod -cを使ってフィルタしたものを示します。
テーブルには3列あり、最初のデータ型はchar(2)、2番目はtext、3番目はintegerです。
全ての行の3列目はNULL値です。
0000000 P G C O P Y \n 377 \r \n \0 \0 \0 \0 \0 \0 0000020 \0 \0 \0 \0 003 \0 \0 \0 002 A F \0 \0 \0 013 A 0000040 F G H A N I S T A N 377 377 377 377 \0 003 0000060 \0 \0 \0 002 A L \0 \0 \0 007 A L B A N I 0000100 A 377 377 377 377 \0 003 \0 \0 \0 002 D Z \0 \0 \0 0000120 007 A L G E R I A 377 377 377 377 \0 003 \0 \0 0000140 \0 002 Z M \0 \0 \0 006 Z A M B I A 377 377 0000160 377 377 \0 003 \0 \0 \0 002 Z W \0 \0 \0 \b Z I 0000200 M B A B W E 377 377 377 377 377 377
There is no <command>COPY</command> statement in the SQL standard.
標準SQLにはCOPY文はありません。
The following syntax was used before <productname>PostgreSQL</productname> version 9.0 and is still supported: 以下の構文は、PostgreSQLバージョン9.0より前に使用されていたもので、まだサポートされています。
COPYtable_name[ (column_name[, ...] ) ] FROM { 'filename' | STDIN } [ [ WITH ] [ BINARY ] [ DELIMITER [ AS ] 'delimiter_character' ] [ NULL [ AS ] 'null_string' ] [ CSV [ HEADER ] [ QUOTE [ AS ] 'quote_character' ] [ ESCAPE [ AS ] 'escape_character' ] [ FORCE NOT NULLcolumn_name[, ...] ] ] ] COPY {table_name[ (column_name[, ...] ) ] | (query) } TO { 'filename' | STDOUT } [ [ WITH ] [ BINARY ] [ DELIMITER [ AS ] 'delimiter_character' ] [ NULL [ AS ] 'null_string' ] [ CSV [ HEADER ] [ QUOTE [ AS ] 'quote_character' ] [ ESCAPE [ AS ] 'escape_character' ] [ FORCE QUOTE {column_name[, ...] | * } ] ] ]
Note that in this syntax, <literal>BINARY</literal> and <literal>CSV</literal> are
treated as independent keywords, not as arguments of a <literal>FORMAT</literal>
option.
この構文では、BINARYとCSVがFORMATオプションの引数ではなく、独立したキーワードとして扱われることに注意してください。
The following syntax was used before <productname>PostgreSQL</productname> version 7.3 and is still supported: 以下の構文は、PostgreSQLバージョン7.3より前に使用されていたもので、まだサポートされています。
COPY [ BINARY ]table_nameFROM { 'filename' | STDIN } [ [USING] DELIMITERS 'delimiter_character' ] [ WITH NULL AS 'null_string' ] COPY [ BINARY ]table_nameTO { 'filename' | STDOUT } [ [USING] DELIMITERS 'delimiter_character' ] [ WITH NULL AS 'null_string' ]