diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml index e6bbcea60b1..206fe2719bb 100644 --- a/doc/src/sgml/ref/psql-ref.sgml +++ b/doc/src/sgml/ref/psql-ref.sgml @@ -1,5 +1,5 @@ @@ -706,7 +706,7 @@ testdb=> \copy table [ ( column_list ) ] { from | to } - { filename | stdin | stdout | - } + { filename | stdin | stdout | pstdin | pstdout } [ with ] [ oids ] [ delimiter [as] 'character' ] @@ -736,18 +736,17 @@ testdb=> - For \copy \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. + class="parameter">stdin | stdout + reads/writes based on the command input and output respectively. + All rows are read from the same source that issued the command, + continuing until \. is read or the stream + reaches EOF. Output is sent to the same place as + command output. To read/write from + psql's standard input or output, use + pstdin or pstdout. This option is useful + for populating tables in-line within a SQL script file. @@ -759,20 +758,6 @@ testdb=> - - - Note the difference in interpretation of - stdin and stdout between - \copy and COPY. - In \copy these always - refer to psql's input and output - 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). - - diff --git a/src/bin/psql/copy.c b/src/bin/psql/copy.c index 9fb35f532de..49b8b8a064d 100644 --- a/src/bin/psql/copy.c +++ b/src/bin/psql/copy.c @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2003, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/copy.c,v 1.42 2004/01/29 12:34:59 neilc Exp $ + * $PostgreSQL: pgsql/src/bin/psql/copy.c,v 1.43 2004/04/12 15:58:52 momjian Exp $ */ #include "postgres_fe.h" #include "copy.h" @@ -62,7 +62,7 @@ struct copy_options char *table; char *column_list; char *file; /* NULL = stdin/stdout */ - bool in_dash; /* true = use src stream not true stdin */ + bool psql_inout; /* true = use psql stdin/stdout */ bool from; bool binary; bool oids; @@ -220,21 +220,18 @@ parse_slash_copy(const char *args) if (strcasecmp(token, "stdin") == 0 || strcasecmp(token, "stdout") == 0) { - result->in_dash = false; + result->psql_inout = false; result->file = NULL; } - else if (strcmp(token, "-") == 0) + else if (strcasecmp(token, "pstdin") == 0 || + strcasecmp(token, "pstdout") == 0) { - /* Can't do this on output */ - if (!result->from) - goto error; - - result->in_dash = true; + result->psql_inout = true; result->file = NULL; } else { - result->in_dash = false; + result->psql_inout = false; result->file = pg_strdup(token); expand_tilde(&result->file); } @@ -394,7 +391,7 @@ do_copy(const char *args) { if (options->file) copystream = fopen(options->file, "r"); - else if (options->in_dash) + else if (!options->psql_inout) copystream = pset.cur_cmd_source; else copystream = stdin; @@ -403,6 +400,8 @@ do_copy(const char *args) { if (options->file) copystream = fopen(options->file, "w"); + else if (!options->psql_inout) + copystream = pset.queryFout; else copystream = stdout; }