1COPY(7) PostgreSQL 16.1 Documentation COPY(7)
2
3
4
6 COPY - copy data between a file and a table
7
9 COPY table_name [ ( column_name [, ...] ) ]
10 FROM { 'filename' | PROGRAM 'command' | STDIN }
11 [ [ WITH ] ( option [, ...] ) ]
12 [ WHERE condition ]
13
14 COPY { table_name [ ( column_name [, ...] ) ] | ( query ) }
15 TO { 'filename' | PROGRAM 'command' | STDOUT }
16 [ [ WITH ] ( option [, ...] ) ]
17
18 where option can be one of:
19
20 FORMAT format_name
21 FREEZE [ boolean ]
22 DELIMITER 'delimiter_character'
23 NULL 'null_string'
24 DEFAULT 'default_string'
25 HEADER [ boolean | MATCH ]
26 QUOTE 'quote_character'
27 ESCAPE 'escape_character'
28 FORCE_QUOTE { ( column_name [, ...] ) | * }
29 FORCE_NOT_NULL ( column_name [, ...] )
30 FORCE_NULL ( column_name [, ...] )
31 ENCODING 'encoding_name'
32
34 COPY moves data between PostgreSQL tables and standard file-system
35 files. COPY TO copies the contents of a table to a file, while COPY
36 FROM copies data from a file to a table (appending the data to whatever
37 is in the table already). COPY TO can also copy the results of a
38 SELECT query.
39
40 If a column list is specified, COPY TO copies only the data in the
41 specified columns to the file. For COPY FROM, each field in the file is
42 inserted, in order, into the specified column. Table columns not
43 specified in the COPY FROM column list will receive their default
44 values.
45
46 COPY with a file name instructs the PostgreSQL server to directly read
47 from or write to a file. The file must be accessible by the PostgreSQL
48 user (the user ID the server runs as) and the name must be specified
49 from the viewpoint of the server. When PROGRAM is specified, the server
50 executes the given command and reads from the standard output of the
51 program, or writes to the standard input of the program. The command
52 must be specified from the viewpoint of the server, and be executable
53 by the PostgreSQL user. When STDIN or STDOUT is specified, data is
54 transmitted via the connection between the client and the server.
55
56 Each backend running COPY will report its progress in the
57 pg_stat_progress_copy view. See Section 28.4.3 for details.
58
60 table_name
61 The name (optionally schema-qualified) of an existing table.
62
63 column_name
64 An optional list of columns to be copied. If no column list is
65 specified, all columns of the table except generated columns will
66 be copied.
67
68 query
69 A SELECT, VALUES, INSERT, UPDATE, or DELETE command whose results
70 are to be copied. Note that parentheses are required around the
71 query.
72
73 For INSERT, UPDATE and DELETE queries a RETURNING clause must be
74 provided, and the target relation must not have a conditional rule,
75 nor an ALSO rule, nor an INSTEAD rule that expands to multiple
76 statements.
77
78 filename
79 The path name of the input or output file. An input file name can
80 be an absolute or relative path, but an output file name must be an
81 absolute path. Windows users might need to use an E'' string and
82 double any backslashes used in the path name.
83
84 PROGRAM
85 A command to execute. In COPY FROM, the input is read from standard
86 output of the command, and in COPY TO, the output is written to the
87 standard input of the command.
88
89 Note that the command is invoked by the shell, so if you need to
90 pass any arguments that come from an untrusted source, you must be
91 careful to strip or escape any special characters that might have a
92 special meaning for the shell. For security reasons, it is best to
93 use a fixed command string, or at least avoid including any user
94 input in it.
95
96 STDIN
97 Specifies that input comes from the client application.
98
99 STDOUT
100 Specifies that output goes to the client application.
101
102 boolean
103 Specifies whether the selected option should be turned on or off.
104 You can write TRUE, ON, or 1 to enable the option, and FALSE, OFF,
105 or 0 to disable it. The boolean value can also be omitted, in which
106 case TRUE is assumed.
107
108 FORMAT
109 Selects the data format to be read or written: text, csv (Comma
110 Separated Values), or binary. The default is text.
111
112 FREEZE
113 Requests copying the data with rows already frozen, just as they
114 would be after running the VACUUM FREEZE command. This is intended
115 as a performance option for initial data loading. Rows will be
116 frozen only if the table being loaded has been created or truncated
117 in the current subtransaction, there are no cursors open and there
118 are no older snapshots held by this transaction. It is currently
119 not possible to perform a COPY FREEZE on a partitioned table.
120
121 Note that all other sessions will immediately be able to see the
122 data once it has been successfully loaded. This violates the normal
123 rules of MVCC visibility and users should be aware of the potential
124 problems this might cause.
125
126 DELIMITER
127 Specifies the character that separates columns within each row
128 (line) of the file. The default is a tab character in text format,
129 a comma in CSV format. This must be a single one-byte character.
130 This option is not allowed when using binary format.
131
132 NULL
133 Specifies the string that represents a null value. The default is
134 \N (backslash-N) in text format, and an unquoted empty string in
135 CSV format. You might prefer an empty string even in text format
136 for cases where you don't want to distinguish nulls from empty
137 strings. This option is not allowed when using binary format.
138
139 Note
140 When using COPY FROM, any data item that matches this string
141 will be stored as a null value, so you should make sure that
142 you use the same string as you used with COPY TO.
143
144 DEFAULT
145 Specifies the string that represents a default value. Each time the
146 string is found in the input file, the default value of the
147 corresponding column will be used. This option is allowed only in
148 COPY FROM, and only when not using binary format.
149
150 HEADER
151 Specifies that the file contains a header line with the names of
152 each column in the file. On output, the first line contains the
153 column names from the table. On input, the first line is discarded
154 when this option is set to true (or equivalent Boolean value). If
155 this option is set to MATCH, the number and names of the columns in
156 the header line must match the actual column names of the table, in
157 order; otherwise an error is raised. This option is not allowed
158 when using binary format. The MATCH option is only valid for COPY
159 FROM commands.
160
161 QUOTE
162 Specifies the quoting character to be used when a data value is
163 quoted. The default is double-quote. This must be a single one-byte
164 character. This option is allowed only when using CSV format.
165
166 ESCAPE
167 Specifies the character that should appear before a data character
168 that matches the QUOTE value. The default is the same as the QUOTE
169 value (so that the quoting character is doubled if it appears in
170 the data). This must be a single one-byte character. This option is
171 allowed only when using CSV format.
172
173 FORCE_QUOTE
174 Forces quoting to be used for all non-NULL values in each specified
175 column. NULL output is never quoted. If * is specified, non-NULL
176 values will be quoted in all columns. This option is allowed only
177 in COPY TO, and only when using CSV format.
178
179 FORCE_NOT_NULL
180 Do not match the specified columns' values against the null string.
181 In the default case where the null string is empty, this means that
182 empty values will be read as zero-length strings rather than nulls,
183 even when they are not quoted. This option is allowed only in COPY
184 FROM, and only when using CSV format.
185
186 FORCE_NULL
187 Match the specified columns' values against the null string, even
188 if it has been quoted, and if a match is found set the value to
189 NULL. In the default case where the null string is empty, this
190 converts a quoted empty string into NULL. This option is allowed
191 only in COPY FROM, and only when using CSV format.
192
193 ENCODING
194 Specifies that the file is encoded in the encoding_name. If this
195 option is omitted, the current client encoding is used. See the
196 Notes below for more details.
197
198 WHERE
199 The optional WHERE clause has the general form
200
201 WHERE condition
202
203 where condition is any expression that evaluates to a result of
204 type boolean. Any row that does not satisfy this condition will not
205 be inserted to the table. A row satisfies the condition if it
206 returns true when the actual row values are substituted for any
207 variable references.
208
209 Currently, subqueries are not allowed in WHERE expressions, and the
210 evaluation does not see any changes made by the COPY itself (this
211 matters when the expression contains calls to VOLATILE functions).
212
214 On successful completion, a COPY command returns a command tag of the
215 form
216
217 COPY count
218
219 The count is the number of rows copied.
220
221 Note
222 psql will print this command tag only if the command was not COPY
223 ... TO STDOUT, or the equivalent psql meta-command \copy ... to
224 stdout. This is to prevent confusing the command tag with the data
225 that was just printed.
226
228 COPY TO can be used only with plain tables, not views, and does not
229 copy rows from child tables or child partitions. For example, COPY
230 table TO copies the same rows as SELECT * FROM ONLY table. The syntax
231 COPY (SELECT * FROM table) TO ... can be used to dump all of the rows
232 in an inheritance hierarchy, partitioned table, or view.
233
234 COPY FROM can be used with plain, foreign, or partitioned tables or
235 with views that have INSTEAD OF INSERT triggers.
236
237 You must have select privilege on the table whose values are read by
238 COPY TO, and insert privilege on the table into which values are
239 inserted by COPY FROM. It is sufficient to have column privileges on
240 the column(s) listed in the command.
241
242 If row-level security is enabled for the table, the relevant SELECT
243 policies will apply to COPY table TO statements. Currently, COPY FROM
244 is not supported for tables with row-level security. Use equivalent
245 INSERT statements instead.
246
247 Files named in a COPY command are read or written directly by the
248 server, not by the client application. Therefore, they must reside on
249 or be accessible to the database server machine, not the client. They
250 must be accessible to and readable or writable by the PostgreSQL user
251 (the user ID the server runs as), not the client. Similarly, the
252 command specified with PROGRAM is executed directly by the server, not
253 by the client application, must be executable by the PostgreSQL user.
254 COPY naming a file or command is only allowed to database superusers or
255 users who are granted one of the roles pg_read_server_files,
256 pg_write_server_files, or pg_execute_server_program, since it allows
257 reading or writing any file or running a program that the server has
258 privileges to access.
259
260 Do not confuse COPY with the psql instruction \copy. \copy invokes
261 COPY FROM STDIN or COPY TO STDOUT, and then fetches/stores the data in
262 a file accessible to the psql client. Thus, file accessibility and
263 access rights depend on the client rather than the server when \copy is
264 used.
265
266 It is recommended that the file name used in COPY always be specified
267 as an absolute path. This is enforced by the server in the case of COPY
268 TO, but for COPY FROM you do have the option of reading from a file
269 specified by a relative path. The path will be interpreted relative to
270 the working directory of the server process (normally the cluster's
271 data directory), not the client's working directory.
272
273 Executing a command with PROGRAM might be restricted by the operating
274 system's access control mechanisms, such as SELinux.
275
276 COPY FROM will invoke any triggers and check constraints on the
277 destination table. However, it will not invoke rules.
278
279 For identity columns, the COPY FROM command will always write the
280 column values provided in the input data, like the INSERT option
281 OVERRIDING SYSTEM VALUE.
282
283 COPY input and output is affected by DateStyle. To ensure portability
284 to other PostgreSQL installations that might use non-default DateStyle
285 settings, DateStyle should be set to ISO before using COPY TO. It is
286 also a good idea to avoid dumping data with IntervalStyle set to
287 sql_standard, because negative interval values might be misinterpreted
288 by a server that has a different setting for IntervalStyle.
289
290 Input data is interpreted according to ENCODING option or the current
291 client encoding, and output data is encoded in ENCODING or the current
292 client encoding, even if the data does not pass through the client but
293 is read from or written to a file directly by the server.
294
295 COPY stops operation at the first error. This should not lead to
296 problems in the event of a COPY TO, but the target table will already
297 have received earlier rows in a COPY FROM. These rows will not be
298 visible or accessible, but they still occupy disk space. This might
299 amount to a considerable amount of wasted disk space if the failure
300 happened well into a large copy operation. You might wish to invoke
301 VACUUM to recover the wasted space.
302
303 FORCE_NULL and FORCE_NOT_NULL can be used simultaneously on the same
304 column. This results in converting quoted null strings to null values
305 and unquoted null strings to empty strings.
306
308 Text Format
309 When the text format is used, the data read or written is a text file
310 with one line per table row. Columns in a row are separated by the
311 delimiter character. The column values themselves are strings generated
312 by the output function, or acceptable to the input function, of each
313 attribute's data type. The specified null string is used in place of
314 columns that are null. COPY FROM will raise an error if any line of
315 the input file contains more or fewer columns than are expected.
316
317 End of data can be represented by a single line containing just
318 backslash-period (\.). An end-of-data marker is not necessary when
319 reading from a file, since the end of file serves perfectly well; it is
320 needed only when copying data to or from client applications using
321 pre-3.0 client protocol.
322
323 Backslash characters (\) can be used in the COPY data to quote data
324 characters that might otherwise be taken as row or column delimiters.
325 In particular, the following characters must be preceded by a backslash
326 if they appear as part of a column value: backslash itself, newline,
327 carriage return, and the current delimiter character.
328
329 The specified null string is sent by COPY TO without adding any
330 backslashes; conversely, COPY FROM matches the input against the null
331 string before removing backslashes. Therefore, a null string such as \N
332 cannot be confused with the actual data value \N (which would be
333 represented as \\N).
334
335 The following special backslash sequences are recognized by COPY FROM:
336
337 ┌─────────┬────────────────────────────┐
338 │Sequence │ Represents │
339 ├─────────┼────────────────────────────┤
340 │\b │ Backspace (ASCII 8) │
341 ├─────────┼────────────────────────────┤
342 │\f │ Form feed (ASCII 12) │
343 ├─────────┼────────────────────────────┤
344 │\n │ Newline (ASCII 10) │
345 ├─────────┼────────────────────────────┤
346 │\r │ Carriage return (ASCII 13) │
347 ├─────────┼────────────────────────────┤
348 │\t │ Tab (ASCII 9) │
349 ├─────────┼────────────────────────────┤
350 │\v │ Vertical tab (ASCII 11) │
351 ├─────────┼────────────────────────────┤
352 │\digits │ Backslash followed by one │
353 │ │ to three octal digits │
354 │ │ specifies │
355 │ │ the byte with that │
356 │ │ numeric code │
357 ├─────────┼────────────────────────────┤
358 │\xdigits │ Backslash x followed by │
359 │ │ one or two hex digits │
360 │ │ specifies │
361 │ │ the byte with that │
362 │ │ numeric code │
363 └─────────┴────────────────────────────┘
364 Presently, COPY TO will never emit an octal or hex-digits backslash
365 sequence, but it does use the other sequences listed above for those
366 control characters.
367
368 Any other backslashed character that is not mentioned in the above
369 table will be taken to represent itself. However, beware of adding
370 backslashes unnecessarily, since that might accidentally produce a
371 string matching the end-of-data marker (\.) or the null string (\N by
372 default). These strings will be recognized before any other backslash
373 processing is done.
374
375 It is strongly recommended that applications generating COPY data
376 convert data newlines and carriage returns to the \n and \r sequences
377 respectively. At present it is possible to represent a data carriage
378 return by a backslash and carriage return, and to represent a data
379 newline by a backslash and newline. However, these representations
380 might not be accepted in future releases. They are also highly
381 vulnerable to corruption if the COPY file is transferred across
382 different machines (for example, from Unix to Windows or vice versa).
383
384 All backslash sequences are interpreted after encoding conversion. The
385 bytes specified with the octal and hex-digit backslash sequences must
386 form valid characters in the database encoding.
387
388 COPY TO will terminate each row with a Unix-style newline (“\n”).
389 Servers running on Microsoft Windows instead output carriage
390 return/newline (“\r\n”), but only for COPY to a server file; for
391 consistency across platforms, COPY TO STDOUT always sends “\n”
392 regardless of server platform. COPY FROM can handle lines ending with
393 newlines, carriage returns, or carriage return/newlines. To reduce the
394 risk of error due to un-backslashed newlines or carriage returns that
395 were meant as data, COPY FROM will complain if the line endings in the
396 input are not all alike.
397
398 CSV Format
399 This format option is used for importing and exporting the Comma
400 Separated Value (CSV) file format used by many other programs, such as
401 spreadsheets. Instead of the escaping rules used by PostgreSQL's
402 standard text format, it produces and recognizes the common CSV
403 escaping mechanism.
404
405 The values in each record are separated by the DELIMITER character. If
406 the value contains the delimiter character, the QUOTE character, the
407 NULL string, a carriage return, or line feed character, then the whole
408 value is prefixed and suffixed by the QUOTE character, and any
409 occurrence within the value of a QUOTE character or the ESCAPE
410 character is preceded by the escape character. You can also use
411 FORCE_QUOTE to force quotes when outputting non-NULL values in specific
412 columns.
413
414 The CSV format has no standard way to distinguish a NULL value from an
415 empty string. PostgreSQL's COPY handles this by quoting. A NULL is
416 output as the NULL parameter string and is not quoted, while a non-NULL
417 value matching the NULL parameter string is quoted. For example, with
418 the default settings, a NULL is written as an unquoted empty string,
419 while an empty string data value is written with double quotes ("").
420 Reading values follows similar rules. You can use FORCE_NOT_NULL to
421 prevent NULL input comparisons for specific columns. You can also use
422 FORCE_NULL to convert quoted null string data values to NULL.
423
424 Because backslash is not a special character in the CSV format, \., the
425 end-of-data marker, could also appear as a data value. To avoid any
426 misinterpretation, a \. data value appearing as a lone entry on a line
427 is automatically quoted on output, and on input, if quoted, is not
428 interpreted as the end-of-data marker. If you are loading a file
429 created by another application that has a single unquoted column and
430 might have a value of \., you might need to quote that value in the
431 input file.
432
433 Note
434 In CSV format, all characters are significant. A quoted value
435 surrounded by white space, or any characters other than DELIMITER,
436 will include those characters. This can cause errors if you import
437 data from a system that pads CSV lines with white space out to some
438 fixed width. If such a situation arises you might need to
439 preprocess the CSV file to remove the trailing white space, before
440 importing the data into PostgreSQL.
441
442 Note
443 CSV format will both recognize and produce CSV files with quoted
444 values containing embedded carriage returns and line feeds. Thus
445 the files are not strictly one line per table row like text-format
446 files.
447
448 Note
449 Many programs produce strange and occasionally perverse CSV files,
450 so the file format is more a convention than a standard. Thus you
451 might encounter some files that cannot be imported using this
452 mechanism, and COPY might produce files that other programs cannot
453 process.
454
455 Binary Format
456 The binary format option causes all data to be stored/read as binary
457 format rather than as text. It is somewhat faster than the text and CSV
458 formats, but a binary-format file is less portable across machine
459 architectures and PostgreSQL versions. Also, the binary format is very
460 data type specific; for example it will not work to output binary data
461 from a smallint column and read it into an integer column, even though
462 that would work fine in text format.
463
464 The binary file format consists of a file header, zero or more tuples
465 containing the row data, and a file trailer. Headers and data are in
466 network byte order.
467
468 Note
469 PostgreSQL releases before 7.4 used a different binary file format.
470
471 File Header
472 The file header consists of 15 bytes of fixed fields, followed by a
473 variable-length header extension area. The fixed fields are:
474
475 Signature
476 11-byte sequence PGCOPY\n\377\r\n\0 — note that the zero byte
477 is a required part of the signature. (The signature is designed
478 to allow easy identification of files that have been munged by
479 a non-8-bit-clean transfer. This signature will be changed by
480 end-of-line-translation filters, dropped zero bytes, dropped
481 high bits, or parity changes.)
482
483 Flags field
484 32-bit integer bit mask to denote important aspects of the file
485 format. Bits are numbered from 0 (LSB) to 31 (MSB). Note that
486 this field is stored in network byte order (most significant
487 byte first), as are all the integer fields used in the file
488 format. Bits 16–31 are reserved to denote critical file format
489 issues; a reader should abort if it finds an unexpected bit set
490 in this range. Bits 0–15 are reserved to signal
491 backwards-compatible format issues; a reader should simply
492 ignore any unexpected bits set in this range. Currently only
493 one flag bit is defined, and the rest must be zero:
494
495 Bit 16
496 If 1, OIDs are included in the data; if 0, not. Oid system
497 columns are not supported in PostgreSQL anymore, but the
498 format still contains the indicator.
499
500 Header extension area length
501 32-bit integer, length in bytes of remainder of header, not
502 including self. Currently, this is zero, and the first tuple
503 follows immediately. Future changes to the format might allow
504 additional data to be present in the header. A reader should
505 silently skip over any header extension data it does not know
506 what to do with.
507
508 The header extension area is envisioned to contain a sequence of
509 self-identifying chunks. The flags field is not intended to tell
510 readers what is in the extension area. Specific design of header
511 extension contents is left for a later release.
512
513 This design allows for both backwards-compatible header additions
514 (add header extension chunks, or set low-order flag bits) and
515 non-backwards-compatible changes (set high-order flag bits to
516 signal such changes, and add supporting data to the extension area
517 if needed).
518
519 Tuples
520 Each tuple begins with a 16-bit integer count of the number of
521 fields in the tuple. (Presently, all tuples in a table will have
522 the same count, but that might not always be true.) Then, repeated
523 for each field in the tuple, there is a 32-bit length word followed
524 by that many bytes of field data. (The length word does not include
525 itself, and can be zero.) As a special case, -1 indicates a NULL
526 field value. No value bytes follow in the NULL case.
527
528 There is no alignment padding or any other extra data between
529 fields.
530
531 Presently, all data values in a binary-format file are assumed to
532 be in binary format (format code one). It is anticipated that a
533 future extension might add a header field that allows per-column
534 format codes to be specified.
535
536 To determine the appropriate binary format for the actual tuple
537 data you should consult the PostgreSQL source, in particular the
538 *send and *recv functions for each column's data type (typically
539 these functions are found in the src/backend/utils/adt/ directory
540 of the source distribution).
541
542 If OIDs are included in the file, the OID field immediately follows
543 the field-count word. It is a normal field except that it's not
544 included in the field-count. Note that oid system columns are not
545 supported in current versions of PostgreSQL.
546
547 File Trailer
548 The file trailer consists of a 16-bit integer word containing -1.
549 This is easily distinguished from a tuple's field-count word.
550
551 A reader should report an error if a field-count word is neither -1
552 nor the expected number of columns. This provides an extra check
553 against somehow getting out of sync with the data.
554
556 The following example copies a table to the client using the vertical
557 bar (|) as the field delimiter:
558
559 COPY country TO STDOUT (DELIMITER '|');
560
561 To copy data from a file into the country table:
562
563 COPY country FROM '/usr1/proj/bray/sql/country_data';
564
565 To copy into a file just the countries whose names start with 'A':
566
567 COPY (SELECT * FROM country WHERE country_name LIKE 'A%') TO '/usr1/proj/bray/sql/a_list_countries.copy';
568
569 To copy into a compressed file, you can pipe the output through an
570 external compression program:
571
572 COPY country TO PROGRAM 'gzip > /usr1/proj/bray/sql/country_data.gz';
573
574 Here is a sample of data suitable for copying into a table from STDIN:
575
576 AF AFGHANISTAN
577 AL ALBANIA
578 DZ ALGERIA
579 ZM ZAMBIA
580 ZW ZIMBABWE
581
582 Note that the white space on each line is actually a tab character.
583
584 The following is the same data, output in binary format. The data is
585 shown after filtering through the Unix utility od -c. The table has
586 three columns; the first has type char(2), the second has type text,
587 and the third has type integer. All the rows have a null value in the
588 third column.
589
590 0000000 P G C O P Y \n 377 \r \n \0 \0 \0 \0 \0 \0
591 0000020 \0 \0 \0 \0 003 \0 \0 \0 002 A F \0 \0 \0 013 A
592 0000040 F G H A N I S T A N 377 377 377 377 \0 003
593 0000060 \0 \0 \0 002 A L \0 \0 \0 007 A L B A N I
594 0000100 A 377 377 377 377 \0 003 \0 \0 \0 002 D Z \0 \0 \0
595 0000120 007 A L G E R I A 377 377 377 377 \0 003 \0 \0
596 0000140 \0 002 Z M \0 \0 \0 006 Z A M B I A 377 377
597 0000160 377 377 \0 003 \0 \0 \0 002 Z W \0 \0 \0 \b Z I
598 0000200 M B A B W E 377 377 377 377 377 377
599
601 There is no COPY statement in the SQL standard.
602
603 The following syntax was used before PostgreSQL version 9.0 and is
604 still supported:
605
606 COPY table_name [ ( column_name [, ...] ) ]
607 FROM { 'filename' | STDIN }
608 [ [ WITH ]
609 [ BINARY ]
610 [ DELIMITER [ AS ] 'delimiter_character' ]
611 [ NULL [ AS ] 'null_string' ]
612 [ CSV [ HEADER ]
613 [ QUOTE [ AS ] 'quote_character' ]
614 [ ESCAPE [ AS ] 'escape_character' ]
615 [ FORCE NOT NULL column_name [, ...] ] ] ]
616
617 COPY { table_name [ ( column_name [, ...] ) ] | ( query ) }
618 TO { 'filename' | STDOUT }
619 [ [ WITH ]
620 [ BINARY ]
621 [ DELIMITER [ AS ] 'delimiter_character' ]
622 [ NULL [ AS ] 'null_string' ]
623 [ CSV [ HEADER ]
624 [ QUOTE [ AS ] 'quote_character' ]
625 [ ESCAPE [ AS ] 'escape_character' ]
626 [ FORCE QUOTE { column_name [, ...] | * } ] ] ]
627
628 Note that in this syntax, BINARY and CSV are treated as independent
629 keywords, not as arguments of a FORMAT option.
630
631 The following syntax was used before PostgreSQL version 7.3 and is
632 still supported:
633
634 COPY [ BINARY ] table_name
635 FROM { 'filename' | STDIN }
636 [ [USING] DELIMITERS 'delimiter_character' ]
637 [ WITH NULL AS 'null_string' ]
638
639 COPY [ BINARY ] table_name
640 TO { 'filename' | STDOUT }
641 [ [USING] DELIMITERS 'delimiter_character' ]
642 [ WITH NULL AS 'null_string' ]
643
645 Section 28.4.3
646
647
648
649PostgreSQL 16.1 2023 COPY(7)