⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 copy.7

📁 PostgreSQL 8.2中增加了很多企业用户所需要的功能和性能上的提高,其开发团队说,该版本将加速更多企业向该数据库移植.核心开发成员之一Bruce Momjian表示,在新版PostgreSQL
💻 7
📖 第 1 页 / 共 2 页
字号:
.\\" auto-generated by docbook2man-spec $Revision: 1.1.1.1 $.TH "COPY" "" "2008-01-03" "SQL - Language Statements" "SQL Commands".SH NAMECOPY \- copy data between a file and a table.SH SYNOPSIS.sp.nfCOPY \fItablename\fR [ ( \fIcolumn\fR [, ...] ) ]    FROM { '\fIfilename\fR' | STDIN }    [ [ WITH ]           [ BINARY ]          [ OIDS ]          [ DELIMITER [ AS ] '\fIdelimiter\fR' ]          [ NULL [ AS ] '\fInull string\fR' ]          [ CSV [ HEADER ]                [ QUOTE [ AS ] '\fIquote\fR' ]                 [ ESCAPE [ AS ] '\fIescape\fR' ]                [ FORCE NOT NULL \fIcolumn\fR [, ...] ]COPY { \fItablename\fR [ ( \fIcolumn\fR [, ...] ) ] | ( \fIquery\fR ) }    TO { '\fIfilename\fR' | STDOUT }    [ [ WITH ]           [ BINARY ]          [ HEADER ]          [ OIDS ]          [ DELIMITER [ AS ] '\fIdelimiter\fR' ]          [ NULL [ AS ] '\fInull string\fR' ]          [ CSV [ HEADER ]                [ QUOTE [ AS ] '\fIquote\fR' ]                 [ ESCAPE [ AS ] '\fIescape\fR' ]                [ FORCE QUOTE \fIcolumn\fR [, ...] ].sp.fi.SH "DESCRIPTION".PP\fBCOPY\fR moves data betweenPostgreSQL tables and standard file-systemfiles. \fBCOPY TO\fR copies the contents of a table\fBto\fR a file, while \fBCOPY FROM\fR copiesdata \fBfrom\fR a file to a table (appending the data towhatever is in the table already). \fBCOPY TO\fRcan also copy the results of a \fBSELECT\fR query..PPIf a list of columns is specified, \fBCOPY\fR willonly copy the data in the specified columns to or from the file.If there are any columns in the table that are not in the column list,\fBCOPY FROM\fR will insert the default values forthose columns..PP\fBCOPY\fR with a file name instructs thePostgreSQL server to directly read fromor write to a file. The file must be accessible to the server andthe name must be specified from the viewpoint of the server. WhenSTDIN or STDOUT isspecified, data is transmitted via the connection between theclient and the server..SH "PARAMETERS".TP\fB\fItablename\fB\fRThe name (optionally schema-qualified) of an existing table..TP\fB\fIcolumn\fB\fRAn optional list of columns to be copied. If no column list isspecified, all columns of the table will be copied..TP\fB\fIquery\fB\fRA SELECT [\fBselect\fR(7)] orVALUES [\fBvalues\fR(7)] commandwhose results are to be copied.Note that parentheses are required around the query..TP\fB\fIfilename\fB\fRThe absolute path name of the input or output file. Windows usersmight need to use an E'' string and double backslashesused as path separators..TP\fBSTDIN\fRSpecifies that input comes from the client application..TP\fBSTDOUT\fRSpecifies that output goes to the client application..TP\fBBINARY\fRCauses all data to be stored or read in binary format ratherthan as text. You cannot specify the \fBDELIMITER\fR,\fBNULL\fR, or \fBCSV\fR options in binary mode..TP\fBOIDS\fRSpecifies copying the OID for each row. (An error is raised ifOIDS is specified for a table that does nothave OIDs, or in the case of copying a \fIquery\fR.).TP\fB\fIdelimiter\fB\fRThe single ASCII character that separates columns within each row(line) of the file. The default is a tab character in text mode,a comma in CSV mode..TP\fB\fInull string\fB\fRThe string that represents a null value. The default is\\N (backslash-N) in text mode, and a emptyvalue with no quotes in CSV mode. You might prefer anempty string even in text mode for cases where you don't want todistinguish nulls from empty strings..sp.RS.B "Note:"When using \fBCOPY FROM\fR, any data item that matchesthis string will be stored as a null value, so you should makesure that you use the same string as you used with\fBCOPY TO\fR..RE.sp.TP\fBCSV\fRSelects Comma Separated Value (CSV) mode..TP\fBHEADER\fRSpecifies the file contains a header line with the names of eachcolumn in the file. On output, the first line contains the column names from the table, and on input, the first line is ignored..TP\fB\fIquote\fB\fRSpecifies the ASCII quotation character in CSV mode.The default is double-quote..TP\fB\fIescape\fB\fRSpecifies the ASCII character that should appear before aQUOTE data character value in CSV mode.The default is the QUOTE value (usually double-quote)..TP\fBFORCE QUOTE\fRIn CSV \fBCOPY TO\fR mode, forces quoting to beused for all non-NULL values in each specified column.NULL output is never quoted..TP\fBFORCE NOT NULL\fRIn CSV \fBCOPY FROM\fR mode, process eachspecified column as though it were quoted and hence not aNULL value. For the default null string inCSV mode (''), this causes missingvalues to be input as zero-length strings..SH "OUTPUTS".PPOn successful completion, a \fBCOPY\fR command returns a commandtag of the form.sp.nfCOPY \fIcount\fR.sp.fiThe \fIcount\fR is the numberof rows copied..SH "NOTES".PP\fBCOPY\fR can only be used with plain tables, notwith views. However, you can write COPY (SELECT * FROM\fIviewname\fR) TO .....PPThe BINARY key word causes all data to bestored/read as binary format rather than as text. It issomewhat faster than the normal text mode, but a binary-formatfile is less portable across machine architectures andPostgreSQL versions..PPYou must have select privilege on the tablewhose values are read by \fBCOPY TO\fR, andinsert privilege on the table into which valuesare inserted by \fBCOPY FROM\fR..PPFiles named in a \fBCOPY\fR command are read or writtendirectly 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 writableby the PostgreSQL user (the user ID theserver runs as), not the client. \fBCOPY\fR naming afile is only allowed to database superusers, since it allows readingor writing any file that the server has privileges to access..PPDo not confuse \fBCOPY\fR with the\fBpsql\fR instruction\fB\\copy\fR. \fB\\copy\fR invokes\fBCOPY FROM STDIN\fR or \fBCOPY TOSTDOUT\fR, and then fetches/stores the data in a fileaccessible to the \fBpsql\fR client. Thus,file accessibility and access rights depend on the client ratherthan the server when \fB\\copy\fR is used..PPIt is recommended that the file name used in \fBCOPY\fRalways be specified as an absolute path. This is enforced by theserver in the case of \fBCOPY TO\fR, but for\fBCOPY FROM\fR you do have the option of reading froma file specified by a relative path. The path will be interpretedrelative to the working directory of the server process (normallythe cluster's data directory), not the client's working directory..PP\fBCOPY FROM\fR will invoke any triggers and checkconstraints on the destination table. However, it will not invoke rules..PP\fBCOPY\fR input and output is affected byDateStyle. To ensure portability to otherPostgreSQL installations that might usenon-default DateStyle settings,DateStyle should be set to ISO beforeusing \fBCOPY TO\fR..PP\fBCOPY\fR stops operation at the first error. Thisshould not lead to problems in the event of a \fBCOPYTO\fR, but the target table will already have receivedearlier rows in a \fBCOPY FROM\fR. These rows will notbe visible or accessible, but they still occupy disk space. This mayamount to a considerable amount of wasted disk space if the failurehappened well into a large copy operation. You may wish to invoke\fBVACUUM\fR to recover the wasted space..SH "FILE FORMATS".SS "TEXT FORMAT".PPWhen \fBCOPY\fR is used without the BINARYor CSV options,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 theoutput function, or acceptable to the input function, of eachattribute's data type. The specified null string is used inplace of columns that are null.\fBCOPY FROM\fR will raise an error if any line of theinput file contains more or fewer columns than are expected.If OIDS is specified, the OID is read or written as the first column,preceding the user data columns..PPEnd of data can be represented by a single line containing justbackslash-period (\\.). An end-of-data marker isnot necessary when reading from a file, since the end of fileserves perfectly well; it is needed only when copying data to or fromclient applications using pre-3.0 client protocol..PPBackslash characters (\\) may be used in the\fBCOPY\fR data to quote data characters that mightotherwise be taken as row or column delimiters. In particular, thefollowing characters \fBmust\fR be preceded by a backslash ifthey appear as part of a column value: backslash itself,newline, carriage return, and the current delimiter character..PPThe specified null string is sent by \fBCOPY TO\fR withoutadding any backslashes; conversely, \fBCOPY FROM\fR matchesthe input against the null string before removing backslashes. Therefore,a null string such as \\N cannot be confused withthe actual data value \\N (which would be representedas \\\\N)..PPThe following special backslash sequences are recognized by\fBCOPY FROM\fR:SequenceRepresents\\bBackspace (ASCII 8)\\fForm feed (ASCII 12)\\nNewline (ASCII 10)\\rCarriage return (ASCII 13)\\tTab (ASCII 9)\\vVertical tab (ASCII 11)\\\fIdigits\fRBackslash followed by one to three octal digits specifiesthe character with that numeric code\\x\fIdigits\fRBackslash x followed by one or two hex digits specifiesthe character with that numeric codePresently, \fBCOPY TO\fR will never emit an octal or hex-digits backslash sequence, but it does use the other sequenceslisted above for those control characters..PPAny other backslashed character that is not mentioned in the above tablewill be taken to represent itself. However, beware of adding backslashes

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -