{"Entry":{"collection":"psql","key":"cmd-63-6f-70-79","name":"\\copy","aliases":["\\copy"],"metadata":{"aliases":["\\copy"],"category":"Data transfer and large objects","content_hash":"03eb58f6edb205fb74059436caad4fd5e2617754ed56a76aacf3658ff95584ad","derived_content_hash":"5b4544c0eda44424745bca137fa4dec4d5699901ee7d64782a5e954dc04ae2ad","documentation_refresh":{"batch":"20261113","original_source_rev":"","versions":{"14":"14.25","15":"15.20","16":"16.16","17":"17.12","18":"18.7","19":"19rc2"}},"imported_at":"2026-09-30T00:40:44.734295+08:00","name":"\\copy","name_zh":"","slug":"cmd-63-6f-70-79","summary":"Performs a frontend (client) copy. This is an operation that runs an SQL COPY command, but instead of the server 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."}},"Definition":{"Collection":"psql","Key":"cmd-63-6f-70-79","SourceDatabase":"center","Version":"18","SourceTable":"psql_command","SourceKey":"cmd-63-6f-70-79","SourceRevision":"1b2d62b4845aa46374f2cb680f95d3392322cc8128646992ae4e18d0e7084915","Facts":{"command":"\\copy","comparison_data":{"definition":"Performs a frontend (client) copy. This is an operation that runs an SQL COPY command, but instead of the server 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. When program is specified, command is executed by psql and the data passed from or to command is routed between the server and the client. Again, the execution privileges are those of the local user, not the server, and no SQL superuser privileges are required. For \\copy ... from stdin , data rows are read from the same source that issued the command, continuing until a line containing only \\. is read or the stream reaches EOF . This option is useful for populating tables in-line within an SQL script file. For \\copy ... to stdout , output is sent to the same place as psql command output, and the COPY count command status is not printed (since it might be confused with a data row). To read/write psql 's standard input or output regardless of the current command source or \\o option, write from pstdin or to pstdout . The syntax of this command is similar to that of the SQL COPY command. All options other than the data source/destination are as specified for COPY . Because of this, special parsing rules apply to the \\copy meta-command. Unlike most other meta-commands, the entire remainder of the line is always taken to be the arguments of \\copy , and neither variable interpolation nor backquote expansion are performed in the arguments. Tip Another way to obtain the same result as \\copy ... to is to use the SQL COPY ... TO STDOUT command and terminate it with \\g filename or \\g | program . Unlike \\copy , this method allows the command to span multiple lines; also, variable interpolation and backquote expansion can be used. Tip These operations are not as efficient as the SQL COPY command with a file or program data source or destination, because all data must pass through the client/server connection. For large amounts of data the SQL command might be preferable.","modifiers":[],"signature":"\\copy { table [ ( column_list ) ] } from { 'filename' | program 'command' | stdin | pstdin } [ [ with ] ( option [, ...] ) ] [ where condition ] \\copy { table [ ( column_list ) ] | ( query ) } to { 'filename' | program 'command' | stdout | pstdout } [ [ with ] ( option [, ...] ) ]","spellings":["\\copy"]},"comparison_hash":"e071767018f7d11f024bce4d06b14a4d3f8ba780a74d277363f0d263427ccc48","description":["Performs a frontend (client) copy. This is an operation that runs an SQL COPY command, but instead of the server 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."],"description_zh":"执行前端（客户端）复制。该操作会运行一个 SQL COPY 命令，但并不是由服务器读取或写入指定文件，而是由 psql 读取或写入文件，并在服务器与本地文件系统之间转送数据。这意味着文件可访问性和权限取决于本地用户，而不是服务器，也不需要 SQL 超级用户权限。","description_zh_html":"\u003cdd\u003e\u003cp\u003e\n        执行前端（客户端）复制。该操作会运行一个 \u003cacronym class=\"acronym\"\u003eSQL\u003c/acronym\u003e\n\u003ca class=\"link\" href=\"/zh/docs/18/sql-copy.html\" title=\"COPY\"\u003e\u003ccode class=\"command\"\u003eCOPY\u003c/code\u003e\u003c/a\u003e 命令，但并不是由服务器读取或写入指定文件，而是由 \u003cspan class=\"application\"\u003epsql\u003c/span\u003e 读取或写入文件，并在服务器与本地文件系统之间转送数据。这意味着文件可访问性和权限取决于本地用户，而不是服务器，也不需要 SQL 超级用户权限。\n\u003c/p\u003e\u003cp\u003e\n        当指定 \u003ccode class=\"literal\"\u003eprogram\u003c/code\u003e 时，\u003cem class=\"replaceable\"\u003e\u003ccode\u003ecommand\u003c/code\u003e\u003c/em\u003e 由 \u003cspan class=\"application\"\u003epsql\u003c/span\u003e 执行，传给 \u003cem class=\"replaceable\"\u003e\u003ccode\u003ecommand\u003c/code\u003e\u003c/em\u003e 的数据或从其中读出的数据都会在服务器与客户端之间转送。再次强调，执行权限属于本地用户，而不是服务器，也不需要 SQL 超级用户权限。\n        \u003c/p\u003e\u003cp\u003e\n        对于 \u003ccode class=\"literal\"\u003e\\copy ... from stdin\u003c/code\u003e，数据行会从发出该命令的同一输入源读取，直到读到仅包含 \u003ccode class=\"literal\"\u003e\\.\u003c/code\u003e 的一行或流到达 \u003cacronym class=\"acronym\"\u003eEOF\u003c/acronym\u003e 为止。这个选项适合在 SQL 脚本文件中以内联方式填充表。对于 \u003ccode class=\"literal\"\u003e\\copy ... to stdout\u003c/code\u003e，输出会发送到与 \u003cspan class=\"application\"\u003epsql\u003c/span\u003e 命令输出相同的位置，并且不会打印 \u003ccode class=\"literal\"\u003eCOPY \u003cem class=\"replaceable\"\u003e\u003ccode\u003ecount\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e 命令状态（因为这可能与数据行混淆）。若要读写 \u003cspan class=\"application\"\u003epsql\u003c/span\u003e 的标准输入或输出，而不受当前命令来源或 \u003ccode class=\"literal\"\u003e\\o\u003c/code\u003e 选项影响，请写成 \u003ccode class=\"literal\"\u003efrom pstdin\u003c/code\u003e 或 \u003ccode class=\"literal\"\u003eto pstdout\u003c/code\u003e。\n        \u003c/p\u003e\u003cp\u003e\n        该命令的语法与 \u003cacronym class=\"acronym\"\u003eSQL\u003c/acronym\u003e \u003ca class=\"link\" href=\"/zh/docs/18/sql-copy.html\" title=\"COPY\"\u003e\u003ccode class=\"command\"\u003eCOPY\u003c/code\u003e\u003c/a\u003e 命令类似。除数据源或目标之外，其他所有选项都与 \u003ccode class=\"command\"\u003eCOPY\u003c/code\u003e 命令中的指定相同。因此，特殊的解析规则适用于\u003ccode class=\"command\"\u003e\\copy\u003c/code\u003e 元命令。与大多数其他元命令不同，整个剩余行始终被视为\u003ccode class=\"command\"\u003e\\copy\u003c/code\u003e 的参数，参数中不执行变量插值或反引号扩展。\n\u003c/p\u003e\u003cdiv class=\"tip\"\u003e\u003ch3 class=\"title\"\u003e提示\u003c/h3\u003e\u003cp\u003e\n        另一种获得与\u003ccode class=\"literal\"\u003e\\copy ... to\u003c/code\u003e 相同结果的方法是使用 \u003cacronym class=\"acronym\"\u003eSQL\u003c/acronym\u003e\n\u003ccode class=\"literal\"\u003eCOPY ... TO STDOUT\u003c/code\u003e 命令，并以\u003ccode class=\"literal\"\u003e\\g \u003cem class=\"replaceable\"\u003e\u003ccode\u003efilename\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\n        或\u003ccode class=\"literal\"\u003e\\g |\u003cem class=\"replaceable\"\u003e\u003ccode\u003eprogram\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e 结束。与\u003ccode class=\"literal\"\u003e\\copy\u003c/code\u003e 不同，这种方法允许命令跨越多行；此外，可以使用变量插值和反引号扩展。\n        \u003c/p\u003e\u003c/div\u003e\u003cdiv class=\"tip\"\u003e\u003ch3 class=\"title\"\u003e提示\u003c/h3\u003e\u003cp\u003e\n        这些操作不如以文件或程序作为数据源或目标的 \u003cacronym class=\"acronym\"\u003eSQL\u003c/acronym\u003e\n\u003ccode class=\"command\"\u003eCOPY\u003c/code\u003e 命令高效，因为所有数据都必须通过客户端/服务器连接传输。对于大量数据，使用 \u003cacronym class=\"acronym\"\u003eSQL\u003c/acronym\u003e\n        命令可能更合适。\n        \u003c/p\u003e\u003c/div\u003e\u003c/dd\u003e","documentation_revision":{"inputs":[{"file":"app-psql.html","kind":"same-version-reviewed-manual","locale":"en","sha256":"af50448485df02bdef2b72b8347192ba029c7082b8d0392ecb17db44ad533aaf","version":"18.7"},{"file":"app-psql.html","kind":"same-version-reviewed-manual","locale":"zh-Hans","sha256":"cb475c53a16d9e06358f5e6c9c5649645db92568cfd319f230c62c9f57ae090b","version":"18.7"}],"release":"18.7","runtime_remeasured":false,"source_revision":"pgdoc:b9f0e7232f60f380d642ac9b99226606c254b552"},"facts":[{"label":"Client","value":"psql 18.7"},{"label":"Case-sensitive spelling","value":"\\copy"}],"facts_zh":[{"label":"客户端","value":"psql 18.7"},{"label":"区分大小写的写法","value":"\\copy"}],"localization":{"documentation_release":"18.7","language":"en","source_language":"en","source_revision":"pgdoc:b9f0e7232f60f380d642ac9b99226606c254b552","status":"same-version-reviewed-manual"},"manual_html":"\u003cdiv\u003e\u003cdl class=\"variablelist\"\u003e\u003cdt id=\"APP-PSQL-META-COMMANDS-COPY\"\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003e\\copy { \u003cem class=\"replaceable\"\u003e\u003ccode\u003etable\u003c/code\u003e\u003c/em\u003e [ ( \u003cem class=\"replaceable\"\u003e\u003ccode\u003ecolumn_list\u003c/code\u003e\u003c/em\u003e ) ] }\n        \u003ccode class=\"literal\"\u003efrom\u003c/code\u003e\n        { \u003cem class=\"replaceable\"\u003e\u003ccode\u003e'filename'\u003c/code\u003e\u003c/em\u003e | program \u003cem class=\"replaceable\"\u003e\u003ccode\u003e'command'\u003c/code\u003e\u003c/em\u003e | stdin | pstdin }\n        [ [ with ] ( \u003cem class=\"replaceable\"\u003e\u003ccode\u003eoption\u003c/code\u003e\u003c/em\u003e [, ...] ) ]\n        [ where \u003cem class=\"replaceable\"\u003e\u003ccode\u003econdition\u003c/code\u003e\u003c/em\u003e ]\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003e\\copy { \u003cem class=\"replaceable\"\u003e\u003ccode\u003etable\u003c/code\u003e\u003c/em\u003e [ ( \u003cem class=\"replaceable\"\u003e\u003ccode\u003ecolumn_list\u003c/code\u003e\u003c/em\u003e ) ] | ( \u003cem class=\"replaceable\"\u003e\u003ccode\u003equery\u003c/code\u003e\u003c/em\u003e ) }\n        \u003ccode class=\"literal\"\u003eto\u003c/code\u003e\n        { \u003cem class=\"replaceable\"\u003e\u003ccode\u003e'filename'\u003c/code\u003e\u003c/em\u003e | program \u003cem class=\"replaceable\"\u003e\u003ccode\u003e'command'\u003c/code\u003e\u003c/em\u003e | stdout | pstdout }\n        [ [ with ] ( \u003cem class=\"replaceable\"\u003e\u003ccode\u003eoption\u003c/code\u003e\u003c/em\u003e [, ...] ) ]\u003c/code\u003e\u003c/span\u003e \u003c/dt\u003e\u003cdd\u003e\u003cp\u003e\n        Performs a frontend (client) copy. This is an operation that\n        runs an SQL \u003ca class=\"link\" href=\"/docs/18/sql-copy.html\" title=\"COPY\"\u003e\u003ccode class=\"command\"\u003eCOPY\u003c/code\u003e\u003c/a\u003e\n        command, but instead of the server\n        reading or writing the specified file,\n        \u003cspan class=\"application\"\u003epsql\u003c/span\u003e reads or writes the file and\n        routes the data between the server and the local file system.\n        This means that file accessibility and privileges are those of\n        the local user, not the server, and no SQL superuser\n        privileges are required.\n        \u003c/p\u003e\u003cp\u003e\n        When \u003ccode class=\"literal\"\u003eprogram\u003c/code\u003e is specified,\n        \u003cem class=\"replaceable\"\u003e\u003ccode\u003ecommand\u003c/code\u003e\u003c/em\u003e is\n        executed by \u003cspan class=\"application\"\u003epsql\u003c/span\u003e and the data passed from\n        or to \u003cem class=\"replaceable\"\u003e\u003ccode\u003ecommand\u003c/code\u003e\u003c/em\u003e is\n        routed between the server and the client.\n        Again, the execution privileges are those of\n        the local user, not the server, and no SQL superuser\n        privileges are required.\n        \u003c/p\u003e\u003cp\u003e\n        For \u003ccode class=\"literal\"\u003e\\copy ... from stdin\u003c/code\u003e, data rows are read from the same\n        source that issued the command, continuing until a line containing\n        only \u003ccode class=\"literal\"\u003e\\.\u003c/code\u003e\n        is read or the stream reaches EOF. This option is useful\n        for populating tables in-line within an SQL script file.\n        For \u003ccode class=\"literal\"\u003e\\copy ... to stdout\u003c/code\u003e, output is sent to the same place\n        as \u003cspan class=\"application\"\u003epsql\u003c/span\u003e command output, and\n        the \u003ccode class=\"literal\"\u003eCOPY \u003cem class=\"replaceable\"\u003e\u003ccode\u003ecount\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e command status is\n        not printed (since it might be confused with a data row).\n        To read/write \u003cspan class=\"application\"\u003epsql\u003c/span\u003e's standard input or\n        output regardless of the current command source or \u003ccode class=\"literal\"\u003e\\o\u003c/code\u003e\n        option, write \u003ccode class=\"literal\"\u003efrom pstdin\u003c/code\u003e or \u003ccode class=\"literal\"\u003eto pstdout\u003c/code\u003e.\n        \u003c/p\u003e\u003cp\u003e\n        The syntax of this command is similar to that of the\n        SQL \u003ca class=\"link\" href=\"/docs/18/sql-copy.html\" title=\"COPY\"\u003e\u003ccode class=\"command\"\u003eCOPY\u003c/code\u003e\u003c/a\u003e\n        command.  All options other than the data source/destination are\n        as specified for \u003ccode class=\"command\"\u003eCOPY\u003c/code\u003e.\n        Because of this, special parsing rules apply to the \u003ccode class=\"command\"\u003e\\copy\u003c/code\u003e\n        meta-command.  Unlike most other meta-commands, the entire remainder\n        of the line is always taken to be the arguments of \u003ccode class=\"command\"\u003e\\copy\u003c/code\u003e,\n        and neither variable interpolation nor backquote expansion are\n        performed in the arguments.\n        \u003c/p\u003e\u003cdiv class=\"tip\"\u003e\u003ch3 class=\"title\"\u003eTip\u003c/h3\u003e\u003cp\u003e\n        Another way to obtain the same result as \u003ccode class=\"literal\"\u003e\\copy\n        ... to\u003c/code\u003e is to use the SQL \u003ccode class=\"literal\"\u003eCOPY\n        ... TO STDOUT\u003c/code\u003e command and terminate it\n        with \u003ccode class=\"literal\"\u003e\\g \u003cem class=\"replaceable\"\u003e\u003ccode\u003efilename\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\n        or \u003ccode class=\"literal\"\u003e\\g |\u003cem class=\"replaceable\"\u003e\u003ccode\u003eprogram\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e.\n        Unlike \u003ccode class=\"literal\"\u003e\\copy\u003c/code\u003e, this method allows the command to\n        span multiple lines; also, variable interpolation and backquote\n        expansion can be used.\n        \u003c/p\u003e\u003c/div\u003e\u003cdiv class=\"tip\"\u003e\u003ch3 class=\"title\"\u003eTip\u003c/h3\u003e\u003cp\u003e\n        These operations are not as efficient as the SQL\n\u003ccode class=\"command\"\u003eCOPY\u003c/code\u003e command with a file or program data source or\n        destination, because all data must pass through the client/server\n        connection.  For large amounts of data the SQL\n        command might be preferable.\n        \u003c/p\u003e\u003c/div\u003e\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e","manual_path":"app-psql.html#APP-PSQL-META-COMMANDS-COPY","modifiers":[],"related":[{"label":"psql command-line options and complete manual","url":"/wiki/tool/psql/?v=18"}],"related_zh":[{"label":"psql 命令行选项及完整手册","url":"/wiki/tool/psql/?v=18"}],"release":{"channel":"stable","evidence_kind":"English manual and source declarations","label":"18.7","major":"18","manifest":{"major":"18","release":"18.7","source_sha256":"441dfae4280cae3e0425e5f876f80559fb0731c140f1aae22b3e5a54d0411bfd","source_url":"https://ftp.postgresql.org/pub/source/v18.7/postgresql-18.7.tar.bz2"},"ref":"https://ftp.postgresql.org/pub/source/v18.7/postgresql-18.7.tar.bz2","revision":"1b2d62b4845aa46374f2cb680f95d3392322cc8128646992ae4e18d0e7084915","source_sha256":"441dfae4280cae3e0425e5f876f80559fb0731c140f1aae22b3e5a54d0411bfd"},"sections":[],"sections_zh":[],"signature":"\\copy { table [ ( column_list ) ] } from { 'filename' | program 'command' | stdin | pstdin } [ [ with ] ( option [, ...] ) ] [ where condition ] \\copy { table [ ( column_list ) ] | ( query ) } to { 'filename' | program 'command' | stdout | pstdout } [ [ with ] ( option [, ...] ) ]","sources":[{"anchor":"APP-PSQL-META-COMMANDS-COPY","file":"app-psql.html","label":"18.7 English manual · app-psql.html","sha256":"af50448485df02bdef2b72b8347192ba029c7082b8d0392ecb17db44ad533aaf","url":"/docs/18/app-psql.html#APP-PSQL-META-COMMANDS-COPY"}],"spellings":["\\copy"],"tables":[{"columns":[{"key":"command","label":"Command"},{"key":"modifiers","label":"Documented suffix modifiers"}],"key":"spellings","rows":[{"command":{"text":"\\copy","url":"/wiki/psql/cmd-63-6f-70-79/?v=18"},"modifiers":"None listed in this signature"}],"title":"Spellings in this manual definition"}],"tables_zh":[{"columns":[{"key":"command","label":"命令"},{"key":"modifiers","label":"手册中的后缀修饰符"}],"key":"spellings","rows":[{"command":{"text":"\\copy","url":"/wiki/psql/cmd-63-6f-70-79/?v=18"},"modifiers":"此语法签名未列出"}],"title":"本版手册中的写法"}],"zh_from":"same-version-manual"},"ManualEvidence":{"manual_path":"app-psql.html#APP-PSQL-META-COMMANDS-COPY","release":{"channel":"stable","evidence_kind":"English manual and source declarations","label":"18.7","major":"18","manifest":{"major":"18","release":"18.7","source_sha256":"441dfae4280cae3e0425e5f876f80559fb0731c140f1aae22b3e5a54d0411bfd","source_url":"https://ftp.postgresql.org/pub/source/v18.7/postgresql-18.7.tar.bz2"},"ref":"https://ftp.postgresql.org/pub/source/v18.7/postgresql-18.7.tar.bz2","revision":"1b2d62b4845aa46374f2cb680f95d3392322cc8128646992ae4e18d0e7084915","source_sha256":"441dfae4280cae3e0425e5f876f80559fb0731c140f1aae22b3e5a54d0411bfd"},"sources":[{"anchor":"APP-PSQL-META-COMMANDS-COPY","file":"app-psql.html","label":"18.7 English manual · app-psql.html","sha256":"af50448485df02bdef2b72b8347192ba029c7082b8d0392ecb17db44ad533aaf","url":"/docs/18/app-psql.html#APP-PSQL-META-COMMANDS-COPY"}]},"MeasuredEvidence":{}},"Text":{"Collection":"psql","Key":"cmd-63-6f-70-79","SourceDatabase":"center","Version":"18","Locale":"en","Title":"\\copy","Summary":"Performs a frontend (client) copy. This is an operation that runs an SQL COPY command, but instead of the server 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.","BodyHTML":"\u003cdiv\u003e\u003cdl\u003e\u003cdt id=\"APP-PSQL-META-COMMANDS-COPY\"\u003e\u003cspan\u003e\u003ccode\u003e\\copy { \u003cem\u003e\u003ccode\u003etable\u003c/code\u003e\u003c/em\u003e [ ( \u003cem\u003e\u003ccode\u003ecolumn_list\u003c/code\u003e\u003c/em\u003e ) ] }\n        \u003ccode\u003efrom\u003c/code\u003e\n        { \u003cem\u003e\u003ccode\u003e\u0026#39;filename\u0026#39;\u003c/code\u003e\u003c/em\u003e | program \u003cem\u003e\u003ccode\u003e\u0026#39;command\u0026#39;\u003c/code\u003e\u003c/em\u003e | stdin | pstdin }\n        [ [ with ] ( \u003cem\u003e\u003ccode\u003eoption\u003c/code\u003e\u003c/em\u003e [, ...] ) ]\n        [ where \u003cem\u003e\u003ccode\u003econdition\u003c/code\u003e\u003c/em\u003e ]\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan\u003e\u003ccode\u003e\\copy { \u003cem\u003e\u003ccode\u003etable\u003c/code\u003e\u003c/em\u003e [ ( \u003cem\u003e\u003ccode\u003ecolumn_list\u003c/code\u003e\u003c/em\u003e ) ] | ( \u003cem\u003e\u003ccode\u003equery\u003c/code\u003e\u003c/em\u003e ) }\n        \u003ccode\u003eto\u003c/code\u003e\n        { \u003cem\u003e\u003ccode\u003e\u0026#39;filename\u0026#39;\u003c/code\u003e\u003c/em\u003e | program \u003cem\u003e\u003ccode\u003e\u0026#39;command\u0026#39;\u003c/code\u003e\u003c/em\u003e | stdout | pstdout }\n        [ [ with ] ( \u003cem\u003e\u003ccode\u003eoption\u003c/code\u003e\u003c/em\u003e [, ...] ) ]\u003c/code\u003e\u003c/span\u003e \u003c/dt\u003e\u003cdd\u003e\u003cp\u003e\n        Performs a frontend (client) copy. This is an operation that\n        runs an SQL \u003ca href=\"/docs/18/sql-copy.html\" title=\"COPY\" rel=\"nofollow\"\u003e\u003ccode\u003eCOPY\u003c/code\u003e\u003c/a\u003e\n        command, but instead of the server\n        reading or writing the specified file,\n        \u003cspan\u003epsql\u003c/span\u003e reads or writes the file and\n        routes the data between the server and the local file system.\n        This means that file accessibility and privileges are those of\n        the local user, not the server, and no SQL superuser\n        privileges are required.\n        \u003c/p\u003e\u003cp\u003e\n        When \u003ccode\u003eprogram\u003c/code\u003e is specified,\n        \u003cem\u003e\u003ccode\u003ecommand\u003c/code\u003e\u003c/em\u003e is\n        executed by \u003cspan\u003epsql\u003c/span\u003e and the data passed from\n        or to \u003cem\u003e\u003ccode\u003ecommand\u003c/code\u003e\u003c/em\u003e is\n        routed between the server and the client.\n        Again, the execution privileges are those of\n        the local user, not the server, and no SQL superuser\n        privileges are required.\n        \u003c/p\u003e\u003cp\u003e\n        For \u003ccode\u003e\\copy ... from stdin\u003c/code\u003e, data rows are read from the same\n        source that issued the command, continuing until a line containing\n        only \u003ccode\u003e\\.\u003c/code\u003e\n        is read or the stream reaches EOF. This option is useful\n        for populating tables in-line within an SQL script file.\n        For \u003ccode\u003e\\copy ... to stdout\u003c/code\u003e, output is sent to the same place\n        as \u003cspan\u003epsql\u003c/span\u003e command output, and\n        the \u003ccode\u003eCOPY \u003cem\u003e\u003ccode\u003ecount\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e command status is\n        not printed (since it might be confused with a data row).\n        To read/write \u003cspan\u003epsql\u003c/span\u003e\u0026#39;s standard input or\n        output regardless of the current command source or \u003ccode\u003e\\o\u003c/code\u003e\n        option, write \u003ccode\u003efrom pstdin\u003c/code\u003e or \u003ccode\u003eto pstdout\u003c/code\u003e.\n        \u003c/p\u003e\u003cp\u003e\n        The syntax of this command is similar to that of the\n        SQL \u003ca href=\"/docs/18/sql-copy.html\" title=\"COPY\" rel=\"nofollow\"\u003e\u003ccode\u003eCOPY\u003c/code\u003e\u003c/a\u003e\n        command.  All options other than the data source/destination are\n        as specified for \u003ccode\u003eCOPY\u003c/code\u003e.\n        Because of this, special parsing rules apply to the \u003ccode\u003e\\copy\u003c/code\u003e\n        meta-command.  Unlike most other meta-commands, the entire remainder\n        of the line is always taken to be the arguments of \u003ccode\u003e\\copy\u003c/code\u003e,\n        and neither variable interpolation nor backquote expansion are\n        performed in the arguments.\n        \u003c/p\u003e\u003cdiv\u003e\u003ch3\u003eTip\u003c/h3\u003e\u003cp\u003e\n        Another way to obtain the same result as \u003ccode\u003e\\copy\n        ... to\u003c/code\u003e is to use the SQL \u003ccode\u003eCOPY\n        ... TO STDOUT\u003c/code\u003e command and terminate it\n        with \u003ccode\u003e\\g \u003cem\u003e\u003ccode\u003efilename\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\n        or \u003ccode\u003e\\g |\u003cem\u003e\u003ccode\u003eprogram\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e.\n        Unlike \u003ccode\u003e\\copy\u003c/code\u003e, this method allows the command to\n        span multiple lines; also, variable interpolation and backquote\n        expansion can be used.\n        \u003c/p\u003e\u003c/div\u003e\u003cdiv\u003e\u003ch3\u003eTip\u003c/h3\u003e\u003cp\u003e\n        These operations are not as efficient as the SQL\n\u003ccode\u003eCOPY\u003c/code\u003e command with a file or program data source or\n        destination, because all data must pass through the client/server\n        connection.  For large amounts of data the SQL\n        command might be preferable.\n        \u003c/p\u003e\u003c/div\u003e\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e","SourceRevision":"1b2d62b4845aa46374f2cb680f95d3392322cc8128646992ae4e18d0e7084915","ContentHash":"b4734e2578eeb8f259eb1f0dfa960988eb6626f2a5ceba64e284426d0305ee72","Payload":{"description":["Performs a frontend (client) copy. This is an operation that runs an SQL COPY command, but instead of the server 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."],"manual_html":"\u003cdiv\u003e\u003cdl class=\"variablelist\"\u003e\u003cdt id=\"APP-PSQL-META-COMMANDS-COPY\"\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003e\\copy { \u003cem class=\"replaceable\"\u003e\u003ccode\u003etable\u003c/code\u003e\u003c/em\u003e [ ( \u003cem class=\"replaceable\"\u003e\u003ccode\u003ecolumn_list\u003c/code\u003e\u003c/em\u003e ) ] }\n        \u003ccode class=\"literal\"\u003efrom\u003c/code\u003e\n        { \u003cem class=\"replaceable\"\u003e\u003ccode\u003e'filename'\u003c/code\u003e\u003c/em\u003e | program \u003cem class=\"replaceable\"\u003e\u003ccode\u003e'command'\u003c/code\u003e\u003c/em\u003e | stdin | pstdin }\n        [ [ with ] ( \u003cem class=\"replaceable\"\u003e\u003ccode\u003eoption\u003c/code\u003e\u003c/em\u003e [, ...] ) ]\n        [ where \u003cem class=\"replaceable\"\u003e\u003ccode\u003econdition\u003c/code\u003e\u003c/em\u003e ]\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003e\\copy { \u003cem class=\"replaceable\"\u003e\u003ccode\u003etable\u003c/code\u003e\u003c/em\u003e [ ( \u003cem class=\"replaceable\"\u003e\u003ccode\u003ecolumn_list\u003c/code\u003e\u003c/em\u003e ) ] | ( \u003cem class=\"replaceable\"\u003e\u003ccode\u003equery\u003c/code\u003e\u003c/em\u003e ) }\n        \u003ccode class=\"literal\"\u003eto\u003c/code\u003e\n        { \u003cem class=\"replaceable\"\u003e\u003ccode\u003e'filename'\u003c/code\u003e\u003c/em\u003e | program \u003cem class=\"replaceable\"\u003e\u003ccode\u003e'command'\u003c/code\u003e\u003c/em\u003e | stdout | pstdout }\n        [ [ with ] ( \u003cem class=\"replaceable\"\u003e\u003ccode\u003eoption\u003c/code\u003e\u003c/em\u003e [, ...] ) ]\u003c/code\u003e\u003c/span\u003e \u003c/dt\u003e\u003cdd\u003e\u003cp\u003e\n        Performs a frontend (client) copy. This is an operation that\n        runs an SQL \u003ca class=\"link\" href=\"/docs/18/sql-copy.html\" title=\"COPY\"\u003e\u003ccode class=\"command\"\u003eCOPY\u003c/code\u003e\u003c/a\u003e\n        command, but instead of the server\n        reading or writing the specified file,\n        \u003cspan class=\"application\"\u003epsql\u003c/span\u003e reads or writes the file and\n        routes the data between the server and the local file system.\n        This means that file accessibility and privileges are those of\n        the local user, not the server, and no SQL superuser\n        privileges are required.\n        \u003c/p\u003e\u003cp\u003e\n        When \u003ccode class=\"literal\"\u003eprogram\u003c/code\u003e is specified,\n        \u003cem class=\"replaceable\"\u003e\u003ccode\u003ecommand\u003c/code\u003e\u003c/em\u003e is\n        executed by \u003cspan class=\"application\"\u003epsql\u003c/span\u003e and the data passed from\n        or to \u003cem class=\"replaceable\"\u003e\u003ccode\u003ecommand\u003c/code\u003e\u003c/em\u003e is\n        routed between the server and the client.\n        Again, the execution privileges are those of\n        the local user, not the server, and no SQL superuser\n        privileges are required.\n        \u003c/p\u003e\u003cp\u003e\n        For \u003ccode class=\"literal\"\u003e\\copy ... from stdin\u003c/code\u003e, data rows are read from the same\n        source that issued the command, continuing until a line containing\n        only \u003ccode class=\"literal\"\u003e\\.\u003c/code\u003e\n        is read or the stream reaches EOF. This option is useful\n        for populating tables in-line within an SQL script file.\n        For \u003ccode class=\"literal\"\u003e\\copy ... to stdout\u003c/code\u003e, output is sent to the same place\n        as \u003cspan class=\"application\"\u003epsql\u003c/span\u003e command output, and\n        the \u003ccode class=\"literal\"\u003eCOPY \u003cem class=\"replaceable\"\u003e\u003ccode\u003ecount\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e command status is\n        not printed (since it might be confused with a data row).\n        To read/write \u003cspan class=\"application\"\u003epsql\u003c/span\u003e's standard input or\n        output regardless of the current command source or \u003ccode class=\"literal\"\u003e\\o\u003c/code\u003e\n        option, write \u003ccode class=\"literal\"\u003efrom pstdin\u003c/code\u003e or \u003ccode class=\"literal\"\u003eto pstdout\u003c/code\u003e.\n        \u003c/p\u003e\u003cp\u003e\n        The syntax of this command is similar to that of the\n        SQL \u003ca class=\"link\" href=\"/docs/18/sql-copy.html\" title=\"COPY\"\u003e\u003ccode class=\"command\"\u003eCOPY\u003c/code\u003e\u003c/a\u003e\n        command.  All options other than the data source/destination are\n        as specified for \u003ccode class=\"command\"\u003eCOPY\u003c/code\u003e.\n        Because of this, special parsing rules apply to the \u003ccode class=\"command\"\u003e\\copy\u003c/code\u003e\n        meta-command.  Unlike most other meta-commands, the entire remainder\n        of the line is always taken to be the arguments of \u003ccode class=\"command\"\u003e\\copy\u003c/code\u003e,\n        and neither variable interpolation nor backquote expansion are\n        performed in the arguments.\n        \u003c/p\u003e\u003cdiv class=\"tip\"\u003e\u003ch3 class=\"title\"\u003eTip\u003c/h3\u003e\u003cp\u003e\n        Another way to obtain the same result as \u003ccode class=\"literal\"\u003e\\copy\n        ... to\u003c/code\u003e is to use the SQL \u003ccode class=\"literal\"\u003eCOPY\n        ... TO STDOUT\u003c/code\u003e command and terminate it\n        with \u003ccode class=\"literal\"\u003e\\g \u003cem class=\"replaceable\"\u003e\u003ccode\u003efilename\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\n        or \u003ccode class=\"literal\"\u003e\\g |\u003cem class=\"replaceable\"\u003e\u003ccode\u003eprogram\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e.\n        Unlike \u003ccode class=\"literal\"\u003e\\copy\u003c/code\u003e, this method allows the command to\n        span multiple lines; also, variable interpolation and backquote\n        expansion can be used.\n        \u003c/p\u003e\u003c/div\u003e\u003cdiv class=\"tip\"\u003e\u003ch3 class=\"title\"\u003eTip\u003c/h3\u003e\u003cp\u003e\n        These operations are not as efficient as the SQL\n\u003ccode class=\"command\"\u003eCOPY\u003c/code\u003e command with a file or program data source or\n        destination, because all data must pass through the client/server\n        connection.  For large amounts of data the SQL\n        command might be preferable.\n        \u003c/p\u003e\u003c/div\u003e\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e","related":[{"label":"psql command-line options and complete manual","url":"/wiki/tool/psql/?v=18"}],"sections":[],"tables":[{"columns":[{"key":"command","label":"Command"},{"key":"modifiers","label":"Documented suffix modifiers"}],"key":"spellings","rows":[{"command":{"text":"\\copy","url":"/wiki/psql/cmd-63-6f-70-79/?v=18"},"modifiers":"None listed in this signature"}],"title":"Spellings in this manual definition"}]}},"RequestedLocale":"en","Fallback":false,"Versions":["10","11","12","13","14","15","16","17","18","19","20"],"Locales":["en","zh-Hans"],"Signatures":null,"Spellings":[{"Version":"18","Ordinal":0,"Command":"\\copy","Signature":"\\copy { table [ ( column_list ) ] } from { 'filename' | program 'command' | stdin | pstdin } [ [ with ] ( option [, ...] ) ] [ where condition ] \\copy { table [ ( column_list ) ] | ( query ) } to { 'filename' | program 'command' | stdout | pstdout } [ [ with ] ( option [, ...] ) ]","Modifiers":[]}],"SQLState":null,"Evidence":null}
