↑↓ 选择 ↵ 打开 ⌫ 改范围 完整检索页

pgsql.cc 提供对 postgresql.org 官网内容的中文翻译,由 Pigsty 团队维护。

百科 / psql 命令 / 查询缓冲区与编辑

\edit

如果指定了 filename ,则编辑该文件;编辑器退出后,文件内容将被复制到当前查询缓冲区。如果没有给出 filename ,则将当前查询缓冲区复制到临时文件中,然后以相同方式进行编辑。或者,如果当前查询缓冲区为空,则将最近执行的查询复制到临时文件中,并以相同方式进行编辑。

当前查看 PostgreSQL 18.6。

说明

如果指定了 filename ,则编辑该文件;编辑器退出后,文件内容将被复制到当前查询缓冲区。如果没有给出 filename ,则将当前查询缓冲区复制到临时文件中,然后以相同方式进行编辑。或者,如果当前查询缓冲区为空,则将最近执行的查询复制到临时文件中,并以相同方式进行编辑。

客户端
psql 18.6
区分大小写的写法
\edit

用法

\e or \edit [ filename ] [ line_number ]

本版手册中的写法

命令手册中的后缀修饰符
\e此语法签名未列出
\edit此语法签名未列出

手册定义

\e 或 \edit [ filename ] [ line_number ]

如果指定了filename,则编辑该文件;编辑器退出后,文件内容将被复制到当前查询缓冲区。如果没有给出filename,则将当前查询缓冲区复制到临时文件中,然后以相同方式进行编辑。或者,如果当前查询缓冲区为空,则将最近执行的查询复制到临时文件中,并以相同方式进行编辑。

如果编辑文件或上一个查询后在未修改文件的情况下退出编辑器,则查询缓冲区将被清除。否则,查询缓冲区的新内容将根据psql的正常规则重新解析,将整个缓冲区视为单行。任何完整的查询将立即执行;也就是说,如果查询缓冲区包含分号或以分号结尾,则执行并从查询缓冲区中删除到该点的所有内容。查询缓冲区中剩余的内容将重新显示。输入分号或\g发送它,或输入\r通过清除查询缓冲区来取消。

将缓冲区视为单行主要影响元命令:在元命令后的缓冲区将被视为元命令的参数,即使它跨越多行。(因此,不能用这种方式创建使用元命令的脚本。请使用\i。)

如果指定了行号,psql将光标定位在文件或查询缓冲区的指定行上。请注意,如果只给出一个全是数字的参数,psql会假定它是一个行号,而不是文件名。

提示

关于如何配置和自定义编辑器,请参见下面的环境。

相关条目

文档与源码

来源构建
版本
18.6
构建
https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2
来源指纹
ee8d1a3612338fd9adf250730cb640fcc5233b5491337cc00a316a44e3a0b9f8

版本比较

PostgreSQL 13 → 14: 属性变化。

以下差异保留原始字段名与英文源描述。

--- PostgreSQL 13
+++ PostgreSQL 14
@@ -1,5 +1,5 @@
 {
-  "definition": "If filename is specified, the file is edited; after the editor exits, the file's content is copied into the current query buffer. If no filename is given, the current query buffer is copied to a temporary file which is then edited in the same fashion. Or, if the current query buffer is empty, the most recently executed query is copied to a temporary file and edited in the same fashion. The new contents of the query buffer are then re-parsed according to the normal rules of psql , treating the whole buffer as a single line. Any complete queries are immediately executed; that is, if the query buffer contains or ends with a semicolon, everything up to that point is executed and removed from the query buffer. Whatever remains in the query buffer is redisplayed. Type semicolon or \\g to send it, or \\r to cancel it by clearing the query buffer. Treating the buffer as a single line primarily affects meta-commands: whatever is in the buffer after a meta-command will be taken as argument(s) to the meta-command, even if it spans multiple lines. (Thus you cannot make meta-command-using scripts this way. Use \\i for that.) If a line number is specified, psql will position the cursor on the specified line of the file or query buffer. Note that if a single all-digits argument is given, psql assumes it is a line number, not a file name. Tip See Environment , below, for how to configure and customize your editor.",
+  "definition": "If filename is specified, the file is edited; after the editor exits, the file's content is copied into the current query buffer. If no filename is given, the current query buffer is copied to a temporary file which is then edited in the same fashion. Or, if the current query buffer is empty, the most recently executed query is copied to a temporary file and edited in the same fashion. If you edit a file or the previous query, and you quit the editor without modifying the file, the query buffer is cleared. Otherwise, the new contents of the query buffer are re-parsed according to the normal rules of psql , treating the whole buffer as a single line. Any complete queries are immediately executed; that is, if the query buffer contains or ends with a semicolon, everything up to that point is executed and removed from the query buffer. Whatever remains in the query buffer is redisplayed. Type semicolon or \\g to send it, or \\r to cancel it by clearing the query buffer. Treating the buffer as a single line primarily affects meta-commands: whatever is in the buffer after a meta-command will be taken as argument(s) to the meta-command, even if it spans multiple lines. (Thus you cannot make meta-command-using scripts this way. Use \\i for that.) If a line number is specified, psql will position the cursor on the specified line of the file or query buffer. Note that if a single all-digits argument is given, psql assumes it is a line number, not a file name. Tip See Environment , below, for how to configure and customize your editor.",
   "modifiers": [],
   "signature": "\\e or \\edit [ filename ] [ line_number ]",
   "spellings": [

比较已记录的接口与属性,排除来源指纹和构建元数据。某个样本中没有记录,不能据此判断实际引入或移除的版本。

相关条目

导出 JSON · 返回psql 命令 · 收录范围为 PostgreSQL 10 至 20;最早采样版本不一定是实际引入版本。