From 04cc4e18dd34f3c301237e60058cc7a00bad41f4 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Tue, 20 Jan 2004 23:48:56 +0000 Subject: Implement '\copy from -' to support reading copy data from the same source the \copy came from. Also, fix prompting logic so that initial and per-line prompts appear for all cases of reading from an interactive terminal. Patch by Mark Feit, with some kibitzing by Tom Lane. --- doc/src/sgml/ref/psql-ref.sgml | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml index 50ea0c910ee..2e17c0310a0 100644 --- a/doc/src/sgml/ref/psql-ref.sgml +++ b/doc/src/sgml/ref/psql-ref.sgml @@ -1,5 +1,5 @@ @@ -705,7 +705,7 @@ testdb=> \copy table [ ( column_list ) ] { from | to } - filename | stdin | stdout + { filename | stdin | stdout | - } [ with ] [ oids ] [ delimiter [as] 'character' ] @@ -720,26 +720,41 @@ testdb=> reading or writing the specified file, psql reads or writes the file and routes the data between the server and the local file system. - This means that file accessibility and privileges are those - of the local user, not the server, and no SQL superuser - privileges are required. + This means that file accessibility and privileges are those of + the local user, not the server, and no SQL superuser + privileges are required. The syntax of the command is similar to that of the - SQL COPY command. (See its - description for the details.) Note that, because of this, + SQL command. Note that, because of this, special parsing rules apply to the \copy command. In particular, the variable substitution rules and backslash escapes do not apply. + + For \copy table from filename operations, + psql adds the option of using a + hyphen instead of filename. This causes + \copy to read rows from the same source that + issued the command, continuing until \. is + read or the stream reaches EOF. This option is + useful for populating tables in-line within a SQL script file. + In contrast, \copy from stdin always reads from + psql's standard input. + + This operation is not as efficient as the SQL COPY command because all data must pass through the client/server connection. For large - amounts of data the other technique may be preferable. + amounts of data the SQL command may be preferable. @@ -747,11 +762,12 @@ testdb=> Note the difference in interpretation of stdin and stdout between - client and server copies: in a client copy these always + \copy and COPY. + In \copy these always refer to psql's input and output - stream. On a server copy stdin comes from - wherever the COPY itself came from (for - example, a script run with the option), and + streams. In COPY, stdin comes + from wherever the COPY itself came from (for + example, a script run with the option), while stdout refers to the query output stream (see \o meta-command below). -- cgit v1.2.3