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

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

百科 / psql 命令 / 查询执行

\bind

为下一次查询执行设置查询参数,并将指定参数传给任意参数占位符( $1 等)。

当前查看 PostgreSQL 18.6。

说明

为下一次查询执行设置查询参数,并将指定参数传给任意参数占位符( $1 等)。

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

用法

\bind [ parameter ] ...

本版手册中的写法

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

手册定义

\bind [ parameter ] ...

为下一次查询执行设置查询参数,并将指定参数传给任意参数占位符($1 等)。

示例:

INSERT INTO tbl1 VALUES ($1, $2) \bind 'first value' 'second value' \g

这对除 \g 之外的查询执行命令也有效,例如 \gx 和 \gset。

此命令会使用扩展查询协议(参见第 54.1.2 节),不同于psql通常使用的简单查询协议。因此,可以用它在psql中测试扩展查询协议。(即使查询没有参数,而且此命令指定了零个参数,也会使用扩展查询协议。)此命令只影响下一条被执行的查询;之后的所有查询默认仍会使用简单查询协议。

相关条目

文档与源码

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

版本比较

PostgreSQL 17 → 18: 属性变化。

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

--- PostgreSQL 17
+++ PostgreSQL 18
@@ -1,5 +1,5 @@
 {
-  "definition": "Sets query parameters for the next query execution, with the specified parameters passed for any parameter placeholders ( $1 etc.). Example: INSERT INTO tbl1 VALUES ($1, $2) \\bind 'first value' 'second value' \\g This also works for query-execution commands besides \\g , such as \\gx and \\gset . This command causes the extended query protocol (see Section 53.1.2 ) to be used, unlike normal psql operation, which uses the simple query protocol. So this command can be useful to test the extended query protocol from psql. (The extended query protocol is used even if the query has no parameters and this command specifies zero parameters.) This command affects only the next query executed; all subsequent queries will use the simple query protocol by default.",
+  "definition": "Sets query parameters for the next query execution, with the specified parameters passed for any parameter placeholders ( $1 etc.). Example: INSERT INTO tbl1 VALUES ($1, $2) \\bind 'first value' 'second value' \\g This also works for query-execution commands besides \\g , such as \\gx and \\gset . This command causes the extended query protocol (see Section 54.1.2 ) to be used, unlike normal psql operation, which uses the simple query protocol. So this command can be useful to test the extended query protocol from psql . (The extended query protocol is used even if the query has no parameters and this command specifies zero parameters.) This command affects only the next query executed; all subsequent queries will use the simple query protocol by default.",
   "modifiers": [],
   "signature": "\\bind [ parameter ] ...",
   "spellings": [

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

相关条目

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