\g
将当前查询缓冲区发送给服务器执行。
当前查看 PostgreSQL 18.6。
说明
将当前查询缓冲区发送给服务器执行。
- 客户端
- psql 18.6
- 区分大小写的写法
- \g
用法
\g [ ( option = value [...]) ] [ filename ] \g [ ( option = value [...]) ] [ | command ]本版手册中的写法
| 命令 | 手册中的后缀修饰符 |
|---|---|
| \g | 此语法签名未列出 |
手册定义
\g [ (option=value[...]) ] [filename]\g [ (option=value[...]) ] [ |command]-
将当前查询缓冲区发送给服务器执行。
如果在
\g后面出现括号,则括号中是用空格分隔的option=value格式选项子句列表。这些子句的解释方式与\psetoptionvalue命令相同,但仅在此查询执行期间生效。在此列表中,=符号周围不允许有空格,但选项子句之间必须有空格。如果=value被省略,则指定的option会按以下命令的方式更改:\psetoption,其中不显式指定value。如果给出了
filename或|command参数,查询输出就会写入指定文件,或通过管道传给指定的 shell 命令,而不是照常显示。只有当查询成功返回零个或多个元组时,才会向文件或命令写入;如果查询失败,或执行的是不返回数据的 SQL 命令,则不会写入。如果当前查询缓冲区为空,则最近发送的查询将被重新执行。除此之外,没有任何参数的
\g基本上等同于一个分号。带有参数的\g提供了一个“一次性”替代\o命令的选择,并且还允许一次性调整通常由\pset设置的输出格式选项。当最后一个参数以
|开头时,该行剩余的全部内容都会被视为要执行的command,其中既不进行变量插值,也不进行反引号扩展。该行剩余部分会直接按字面传给 shell。
相关条目
文档与源码
来源构建
- 版本
- 18.6
- 构建
- https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2
- 来源指纹
ee8d1a3612338fd9adf250730cb640fcc5233b5491337cc00a316a44e3a0b9f8
版本比较
PostgreSQL 12 → 13: 属性变化。
以下差异保留原始字段名与英文源描述。
--- PostgreSQL 12
+++ PostgreSQL 13
@@ -1,7 +1,7 @@
{
- "definition": "Sends the current query buffer to the server for execution. If an argument is given, the query's output is written to the named file or piped to the given shell command, instead of displaying it as usual. The file or command is written to only if the query successfully returns zero or more tuples, not if the query fails or is a non-data-returning SQL command. If the current query buffer is empty, the most recently sent query is re-executed instead. Except for that behavior, \\g without an argument is essentially equivalent to a semicolon. A \\g with argument is a “ one-shot ” alternative to the \\o command. If the argument begins with | , then the entire remainder of the line is taken to be the command to execute, and neither variable interpolation nor backquote expansion are performed in it. The rest of the line is simply passed literally to the shell.",
+ "definition": "Sends the current query buffer to the server for execution. If parentheses appear after \\g , they surround a space-separated list of option = value formatting-option clauses, which are interpreted in the same way as \\pset option value commands, but take effect only for the duration of this query. In this list, spaces are not allowed around = signs, but are required between option clauses. If = value is omitted, the named option is changed in the same way as for \\pset option with no explicit value . If a filename or | command argument is given, the query's output is written to the named file or piped to the given shell command, instead of displaying it as usual. The file or command is written to only if the query successfully returns zero or more tuples, not if the query fails or is a non-data-returning SQL command. If the current query buffer is empty, the most recently sent query is re-executed instead. Except for that behavior, \\g without any arguments is essentially equivalent to a semicolon. With arguments, \\g provides a “ one-shot ” alternative to the \\o command, and additionally allows one-shot adjustments of the output formatting options normally set by \\pset . When the last argument begins with | , the entire remainder of the line is taken to be the command to execute, and neither variable interpolation nor backquote expansion are performed in it. The rest of the line is simply passed literally to the shell.",
"modifiers": [],
- "signature": "\\g [ filename ] \\g [ | command ]",
+ "signature": "\\g [ ( option = value [...]) ] [ filename ] \\g [ ( option = value [...]) ] [ | command ]",
"spellings": [
"\\g"
]
比较已记录的接口与属性,排除来源指纹和构建元数据。某个样本中没有记录,不能据此判断实际引入或移除的版本。
相关条目
导出 JSON · 返回psql 命令 · 收录范围为 PostgreSQL 10 至 20;最早采样版本不一定是实际引入版本。