Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitabdabeb

Browse files
committed
Change psql \copy stdin/stdout to read from command input/output.
Add pstdin/pstdout to read from psql's stdin/stdout.BACKWARD INCOMPATIBLE CHANGE
1 parent7b3189c commitabdabeb

File tree

2 files changed

+22
-38
lines changed

2 files changed

+22
-38
lines changed

‎doc/src/sgml/ref/psql-ref.sgml

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.109 2004/03/30 15:54:33 momjian Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.110 2004/04/12 15:58:52 momjian Exp $
33
PostgreSQL documentation
44
-->
55

@@ -706,7 +706,7 @@ testdb=>
706706
<term><literal>\copy <replaceable class="parameter">table</replaceable>
707707
[ ( <replaceable class="parameter">column_list</replaceable> ) ]
708708
{ <literal>from</literal> | <literal>to</literal> }
709-
{ <replaceable class="parameter">filename</replaceable> | stdin | stdout |- }
709+
{ <replaceable class="parameter">filename</replaceable> | stdin | stdout |pstdin | pstdout }
710710
[ <literal>with</literal> ]
711711
[ <literal>oids</literal> ]
712712
[ <literal>delimiter [as] </literal> '<replaceable class="parameter">character</replaceable>' ]
@@ -736,18 +736,17 @@ testdb=>
736736
</para>
737737

738738
<para>
739-
For<literal>\copy <replaceable
739+
<literal>\copy <replaceable
740740
class="parameter">table</replaceable> from <replaceable
741-
class="parameter">filename</replaceable></literal> operations,
742-
<application>psql</application> adds the option of using a
743-
hyphen instead of <replaceable
744-
class="parameter">filename</replaceable>. This causes
745-
<literal>\copy</literal> to read rows from the same source that
746-
issued the command, continuing until <literal>\.</literal> is
747-
read or the stream reaches <acronym>EOF</>. This option is
748-
useful for populating tables in-line within a SQL script file.
749-
In contrast, <literal>\copy from stdin</> always reads from
750-
<application>psql</application>'s standard input.
741+
class="parameter">stdin | stdout</replaceable></literal>
742+
reads/writes based on the command input and output respectively.
743+
All rows are read from the same source that issued the command,
744+
continuing until <literal>\.</literal> is read or the stream
745+
reaches <acronym>EOF</>. Output is sent to the same place as
746+
command output. To read/write from
747+
<application>psql</application>'s standard input or output, use
748+
<literal>pstdin</> or <literal>pstdout</>. This option is useful
749+
for populating tables in-line within a SQL script file.
751750
</para>
752751

753752
<tip>
@@ -759,20 +758,6 @@ testdb=>
759758
</para>
760759
</tip>
761760

762-
<note>
763-
<para>
764-
Note the difference in interpretation of
765-
<literal>stdin</literal> and <literal>stdout</literal> between
766-
<literal>\copy</literal> and <command>COPY</command>.
767-
In <literal>\copy</literal> these always
768-
refer to <application>psql</application>'s input and output
769-
streams. In <command>COPY</command>, <literal>stdin</literal> comes
770-
from wherever the <command>COPY</command> itself came from (for
771-
example, a script run with the <option>-f</option> option), while
772-
<literal>stdout</literal> refers to the query output stream (see
773-
<command>\o</command> meta-command below).
774-
</para>
775-
</note>
776761
</listitem>
777762
</varlistentry>
778763

‎src/bin/psql/copy.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/copy.c,v 1.42 2004/01/29 12:34:59 neilc Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/copy.c,v 1.43 2004/04/12 15:58:52 momjian Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"copy.h"
@@ -62,7 +62,7 @@ struct copy_options
6262
char*table;
6363
char*column_list;
6464
char*file;/* NULL = stdin/stdout */
65-
boolin_dash;/* true = usesrc stream not truestdin */
65+
boolpsql_inout;/* true = usepsqlstdin/stdout */
6666
boolfrom;
6767
boolbinary;
6868
booloids;
@@ -220,21 +220,18 @@ parse_slash_copy(const char *args)
220220
if (strcasecmp(token,"stdin")==0||
221221
strcasecmp(token,"stdout")==0)
222222
{
223-
result->in_dash= false;
223+
result->psql_inout= false;
224224
result->file=NULL;
225225
}
226-
elseif (strcmp(token,"-")==0)
226+
elseif (strcasecmp(token,"pstdin")==0||
227+
strcasecmp(token,"pstdout")==0)
227228
{
228-
/* Can't do this on output */
229-
if (!result->from)
230-
gotoerror;
231-
232-
result->in_dash= true;
229+
result->psql_inout= true;
233230
result->file=NULL;
234231
}
235232
else
236233
{
237-
result->in_dash= false;
234+
result->psql_inout= false;
238235
result->file=pg_strdup(token);
239236
expand_tilde(&result->file);
240237
}
@@ -394,7 +391,7 @@ do_copy(const char *args)
394391
{
395392
if (options->file)
396393
copystream=fopen(options->file,"r");
397-
elseif (options->in_dash)
394+
elseif (!options->psql_inout)
398395
copystream=pset.cur_cmd_source;
399396
else
400397
copystream=stdin;
@@ -403,6 +400,8 @@ do_copy(const char *args)
403400
{
404401
if (options->file)
405402
copystream=fopen(options->file,"w");
403+
elseif (!options->psql_inout)
404+
copystream=pset.queryFout;
406405
else
407406
copystream=stdout;
408407
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp