Postgres 节点#
¥Postgres node
使用 Postgres 节点自动化 Postgres 中的工作,并将 Postgres 与其他应用集成。n8n 内置支持多种 Postgres 功能,包括执行查询以及在数据库中插入和更新行。
¥Use the Postgres node to automate work in Postgres, and integrate Postgres with other applications. n8n has built-in support for a wide range of Postgres features, including executing queries, as well as inserting and updating rows in a database.
本页列出了 Postgres 节点支持的操作列表以及更多资源的链接。
¥On this page, you'll find a list of operations the Postgres node supports and links to more resources.
Credentials
请参阅 Postgres 凭据 以了解有关设置身份验证的指导。
¥Refer to Postgres credentials for guidance on setting up authentication.
This node can be used as an AI tool
This node can be used to enhance the capabilities of an AI agent. When used in this way, many parameters can be set automatically, or with information directed by AI - find out more in the AI tool parameters documentation.
操作#
¥Operations
- 删除:删除整个表或表中的行。
¥Delete: Delete an entire table or rows in a table
- 执行查询:执行 SQL 查询
¥Execute Query: Execute an SQL query
- 插入:在表中插入行
¥Insert: Insert rows in a table
- 插入或更新:在表中插入或更新行
¥Insert or Update: Insert or update rows in a table
- 选择:从表格中选择行
¥Select: Select rows from a table
- 更新:更新表格中的行
¥Update: Update rows in a table
删除#
¥Delete
使用此操作可删除整个表格或表格中的行。
¥Use this operation to delete an entire table or rows in a table.
请输入以下参数:
¥Enter these parameters:
- 用于连接的凭据:创建或选择现有 Postgres 凭据。
¥Credential to connect with: Create or select an existing Postgres credential.
- 操作:选择“删除”。
¥Operation: Select Delete.
- 架构:请选择包含你要处理的表的架构。选择“从列表”从下拉列表中选择架构,或选择“按名称”输入架构名称。
¥Schema: Choose the schema that contains the table you want to work on. Select From list to choose the schema from the dropdown list or By Name to enter the schema name.
- 表:选择要处理的表格。选择“从列表”从下拉列表中选择表格,或选择“通过名称”输入表格名称。
¥Table: Choose the table that you want to work on. Select From list to choose the table from the dropdown list or By Name to enter the table name.
- 命令:要执行的删除操作:
¥Command: The deletion action to take:
-
截断:移除表格数据,但保留表格结构。
¥Truncate: Removes the table's data but preserves the table's structure.
- 重启序列:是否在截断过程中将自动递增列重置为其初始值。
¥Restart Sequences: Whether to reset auto increment columns to their initial values as part of the Truncate process.
-
删除:删除符合 "选择“行”。" 条件的行。如果你未选择任何内容,Postgres 将删除所有行。
¥Delete: Delete the rows that match the "Select Rows" condition. If you don't select anything, Postgres deletes all rows.
- 选择“行”:定义用于匹配行的列、运算符和值。
¥Select Rows: Define a Column, Operator, and Value to match rows on.
- 合并条件:如何在 "选择“行”。" 中组合条件?“与”逻辑要求所有条件都为真,而“或”逻辑要求至少一个条件为真。
¥Combine Conditions: How to combine the conditions in "Select Rows". AND requires all conditions to be true, while OR requires at least one condition to be true.
-
删除:永久删除表的数据和结构。
¥Drop: Deletes the table's data and structure permanently.
删除选项#
¥Delete options
- 级联:是否同时删除所有依赖于该表的对象,例如视图和序列。使用“截断”或“删除”命令时可用。
¥Cascade: Whether to also drop all objects that depend on the table, like views and sequences. Available if using Truncate or Drop commands.
- 连接超时:尝试连接到数据库的秒数。
¥Connection Timeout: The number of seconds to try to connect to the database.
- 空闲连接关闭延迟:等待空闲连接直至将其关闭的秒数。
¥Delay Closing Idle Connection: The number of seconds to wait before considering idle connections eligible for closing.
- 查询批处理:向数据库发送查询的方式:
¥Query Batching: The way to send queries to the database:
-
单查询:针对所有传入项的单个查询。
¥Single Query: A single query for all incoming items.
-
独立:对执行的每个传入项执行一个查询。
¥Independently: Execute one query per incoming item of the execution.
-
事务:执行事务中的所有查询。如果发生故障,Postgres 会回滚所有更改。
¥Transaction: Execute all queries in a transaction. If a failure occurs, Postgres rolls back all changes.
-
输出大格式数字:
NUMERIC和BIGINT列的输出格式:
¥Output Large-Format Numbers As: The format to output NUMERIC and BIGINT columns as:
-
数字:用于接收标准数字。
¥Numbers: Use this for standard numbers.
-
文本:如果你预期输入的数字长度超过 16 位,请使用此选项。如果没有此设置,数字可能不正确。
¥Text: Use this if you expect numbers longer than 16 digits. Without this, numbers may be incorrect.
执行查询#
¥Execute Query
使用此操作执行 SQL 查询。
¥Use this operation to execute an SQL query.
请输入以下参数:
¥Enter these parameters:
- 用于连接的凭据:创建或选择现有 Postgres 凭据。
¥Credential to connect with: Create or select an existing Postgres credential.
- 操作:选择“执行查询”。
¥Operation: Select Execute Query.
- 查询:要执行的 SQL 查询。你可以使用 n8n expressions 和令牌(例如
$1、$2和$3)来构建 预编译语句,以便配合 查询参数 使用。
¥Query: The SQL query to execute. You can use n8n expressions and tokens like $1, $2, and $3 to build prepared statements to use with query parameters.
执行查询选项#
¥Execute Query options
- 连接超时:尝试连接到数据库的秒数。
¥Connection Timeout: The number of seconds to try to connect to the database.
- 空闲连接关闭延迟:等待空闲连接直至将其关闭的秒数。
¥Delay Closing Idle Connection: The number of seconds to wait before considering idle connections eligible for closing.
- 查询批处理:向数据库发送查询的方式:
¥Query Batching: The way to send queries to the database:
-
单查询:针对所有传入项的单个查询。
¥Single Query: A single query for all incoming items.
-
独立:对执行的每个传入项执行一个查询。
¥Independently: Execute one query per incoming item of the execution.
-
事务:执行事务中的所有查询。如果发生故障,Postgres 会回滚所有更改。
¥Transaction: Execute all queries in a transaction. If a failure occurs, Postgres rolls back all changes.
-
查询参数:要用作 查询参数 的值列表(以逗号分隔)。
¥Query Parameters: A comma-separated list of values that you want to use as query parameters.
- 输出大格式数字:
NUMERIC和BIGINT列的输出格式:
¥Output Large-Format Numbers As: The format to output NUMERIC and BIGINT columns as:
-
数字:用于接收标准数字。
¥Numbers: Use this for standard numbers.
-
文本:如果你预期输入的数字长度超过 16 位,请使用此选项。如果没有此设置,数字可能不正确。
¥Text: Use this if you expect numbers longer than 16 digits. Without this, numbers may be incorrect.
-
将空字符串替换为 NULL:是否将输入中的空字符串替换为 NULL。处理从电子表格软件导出的数据时,此功能可能很有用。
¥Replace Empty Strings with NULL: Whether to replace empty strings with NULL in input. This may be useful when working with data exported from spreadsheet software.
插入#
¥Insert
使用此操作在表中插入行。
¥Use this operation to insert rows in a table.
请输入以下参数:
¥Enter these parameters:
- 用于连接的凭据:创建或选择现有 Postgres 凭据。
¥Credential to connect with: Create or select an existing Postgres credential.
- 操作:选择“插入”。
¥Operation: Select Insert.
- 架构:请选择包含你要处理的表的架构。选择“从列表”从下拉列表中选择架构,或选择“按名称”输入架构名称。
¥Schema: Choose the schema that contains the table you want to work on. Select From list to choose the schema from the dropdown list or By Name to enter the schema name.
- 表:选择要处理的表格。选择“从列表”从下拉列表中选择表格,或选择“通过名称”输入表格名称。
¥Table: Choose the table that you want to work on. Select From list to choose the table from the dropdown list or By Name to enter the table name.
- 映射列模式:如何将列名映射到传入数据?
¥Mapping Column Mode: How to map column names to incoming data:
-
手动映射每一列:选择每列的值。
¥Map Each Column Manually: Select the values to use for each column.
-
自动映射:自动将传入数据映射到 Postgres 数据库中匹配的列名。为确保此功能正常工作,传入的数据字段名称必须与 Postgres 数据库中的列名称匹配。如有必要,请考虑在此节点前使用 编辑字段(设置)节点 来根据需要调整格式。
¥Map Automatically: Automatically map incoming data to matching column names in Postgres. The incoming data field names must match the column names in Postgres for this to work. If necessary, consider using the edit fields (set) node before this node to adjust the format as needed.
插入选项#
¥Insert options
- 连接超时:尝试连接到数据库的秒数。
¥Connection Timeout: The number of seconds to try to connect to the database.
- 空闲连接关闭延迟:等待空闲连接直至将其关闭的秒数。
¥Delay Closing Idle Connection: The number of seconds to wait before considering idle connections eligible for closing.
- 查询批处理:向数据库发送查询的方式:
¥Query Batching: The way to send queries to the database:
-
单查询:针对所有传入项的单个查询。
¥Single Query: A single query for all incoming items.
-
独立:对执行的每个传入项执行一个查询。
¥Independently: Execute one query per incoming item of the execution.
-
事务:执行事务中的所有查询。如果发生故障,Postgres 会回滚所有更改。
¥Transaction: Execute all queries in a transaction. If a failure occurs, Postgres rolls back all changes.
-
输出列:选择要输出的列。你可以从可用列列表中选择,也可以使用 expressions 指定 ID。
¥Output Columns: Choose which columns to output. You can select from a list of available columns or specify IDs using expressions.
- 输出大格式数字:
NUMERIC和BIGINT列的输出格式:
¥Output Large-Format Numbers As: The format to output NUMERIC and BIGINT columns as:
-
数字:用于接收标准数字。
¥Numbers: Use this for standard numbers.
-
文本:如果你预期输入的数字长度超过 16 位,请使用此选项。如果没有此设置,数字可能不正确。
¥Text: Use this if you expect numbers longer than 16 digits. Without this, numbers may be incorrect.
-
冲突时跳过:如果插入违反唯一性或排除性约束,是否跳过该行而不是抛出错误。
¥Skip on Conflict: Whether to skip the row if the insert violates a unique or exclusion constraint instead of throwing an error.
- 将空字符串替换为 NULL:是否将输入中的空字符串替换为 NULL。处理从电子表格软件导出的数据时,此功能可能很有用。
¥Replace Empty Strings with NULL: Whether to replace empty strings with NULL in input. This may be useful when working with data exported from spreadsheet software.
插入或更新#
¥Insert or Update
使用此操作在表中插入或更新行。
¥Use this operation to insert or update rows in a table.
请输入以下参数:
¥Enter these parameters:
- 用于连接的凭据:创建或选择现有 Postgres 凭据。
¥Credential to connect with: Create or select an existing Postgres credential.
- 操作:选择“插入”或“更新”。
¥Operation: Select Insert or Update.
- 架构:请选择包含你要处理的表的架构。选择“从列表”从下拉列表中选择架构,或选择“按名称”输入架构名称。
¥Schema: Choose the schema that contains the table you want to work on. Select From list to choose the schema from the dropdown list or By Name to enter the schema name.
- 表:选择要处理的表格。选择“从列表”从下拉列表中选择表格,或选择“通过名称”输入表格名称。
¥Table: Choose the table that you want to work on. Select From list to choose the table from the dropdown list or By Name to enter the table name.
- 映射列模式:如何将列名映射到传入数据?
¥Mapping Column Mode: How to map column names to incoming data:
-
手动映射每一列:选择每列的值。
¥Map Each Column Manually: Select the values to use for each column.
-
自动映射:自动将传入数据映射到 Postgres 数据库中匹配的列名。为确保此功能正常工作,传入的数据字段名称必须与 Postgres 数据库中的列名称匹配。如有必要,请考虑在此节点前使用 编辑字段(设置)节点 来根据需要调整格式。
¥Map Automatically: Automatically map incoming data to matching column names in Postgres. The incoming data field names must match the column names in Postgres for this to work. If necessary, consider using the edit fields (set) node before this node to adjust the format as needed.
插入或更新选项#
¥Insert or Update options
- 连接超时:尝试连接到数据库的秒数。
¥Connection Timeout: The number of seconds to try to connect to the database.
- 空闲连接关闭延迟:等待空闲连接直至将其关闭的秒数。
¥Delay Closing Idle Connection: The number of seconds to wait before considering idle connections eligible for closing.
- 查询批处理:向数据库发送查询的方式:
¥Query Batching: The way to send queries to the database:
-
单查询:针对所有传入项的单个查询。
¥Single Query: A single query for all incoming items.
-
独立:对执行的每个传入项执行一个查询。
¥Independently: Execute one query per incoming item of the execution.
-
事务:执行事务中的所有查询。如果发生故障,Postgres 会回滚所有更改。
¥Transaction: Execute all queries in a transaction. If a failure occurs, Postgres rolls back all changes.
-
输出列:选择要输出的列。你可以从可用列列表中选择,也可以使用 expressions 指定 ID。
¥Output Columns: Choose which columns to output. You can select from a list of available columns or specify IDs using expressions.
- 输出大格式数字:
NUMERIC和BIGINT列的输出格式:
¥Output Large-Format Numbers As: The format to output NUMERIC and BIGINT columns as:
-
数字:用于接收标准数字。
¥Numbers: Use this for standard numbers.
-
文本:如果你预期输入的数字长度超过 16 位,请使用此选项。如果没有此设置,数字可能不正确。
¥Text: Use this if you expect numbers longer than 16 digits. Without this, numbers may be incorrect.
-
将空字符串替换为 NULL:是否将输入中的空字符串替换为 NULL。处理从电子表格软件导出的数据时,此功能可能很有用。
¥Replace Empty Strings with NULL: Whether to replace empty strings with NULL in input. This may be useful when working with data exported from spreadsheet software.
选择#
¥Select
使用此操作选择表格中的行。
¥Use this operation to select rows in a table.
请输入以下参数:
¥Enter these parameters:
- 用于连接的凭据:创建或选择现有 Postgres 凭据。
¥Credential to connect with: Create or select an existing Postgres credential.
- 操作:选择“选择”。
¥Operation: Select Select.
- 架构:请选择包含你要处理的表的架构。选择“从列表”从下拉列表中选择架构,或选择“按名称”输入架构名称。
¥Schema: Choose the schema that contains the table you want to work on. Select From list to choose the schema from the dropdown list or By Name to enter the schema name.
- 表:选择要处理的表格。选择“从列表”从下拉列表中选择表格,或选择“通过名称”输入表格名称。
¥Table: Choose the table that you want to work on. Select From list to choose the table from the dropdown list or By Name to enter the table name.
- 返回全部:是否返回所有结果,还是仅返回指定数量范围内的结果。
¥Return All: Whether to return all results or only up to a given limit.
- 限制:禁用“全部返回”时要返回的最大项目数。
¥Limit: The maximum number of items to return when Return All is disabled.
- 选择“行”:设置选择行的条件。定义用于匹配行的列、运算符和值。如果你未选择任何内容,Postgres 将选择所有行。
¥Select Rows: Set the conditions to select rows. Define a Column, Operator, and Value to match rows on. If you don't select anything, Postgres selects all rows.
- 合并条件:如何在“选择行”中组合条件?“与”逻辑要求所有条件都为真,而“或”逻辑要求至少一个条件为真。
¥Combine Conditions: How to combine the conditions in Select Rows. AND requires all conditions to be true, while OR requires at least one condition to be true.
- 排序:选择如何对选定的行进行排序。从列表中或按 ID 选择列,并设置排序方向。
¥Sort: Choose how to sort the selected rows. Choose a Column from a list or by ID and a sort Direction.
选择选项#
¥Select options
- 连接超时:尝试连接到数据库的秒数。
¥Connection Timeout: The number of seconds to try to connect to the database.
- 空闲连接关闭延迟:等待空闲连接直至将其关闭的秒数。
¥Delay Closing Idle Connection: The number of seconds to wait before considering idle connections eligible for closing.
- 查询批处理:向数据库发送查询的方式:
¥Query Batching: The way to send queries to the database:
-
单查询:针对所有传入项的单个查询。
¥Single Query: A single query for all incoming items.
-
独立:对执行的每个传入项执行一个查询。
¥Independently: Execute one query per incoming item of the execution.
-
事务:执行事务中的所有查询。如果发生故障,Postgres 会回滚所有更改。
¥Transaction: Execute all queries in a transaction. If a failure occurs, Postgres rolls back all changes.
-
输出列:选择要输出的列。你可以从可用列列表中选择,也可以使用 expressions 指定 ID。
¥Output Columns: Choose which columns to output. You can select from a list of available columns or specify IDs using expressions.
- 输出大格式数字:
NUMERIC和BIGINT列的输出格式:
¥Output Large-Format Numbers As: The format to output NUMERIC and BIGINT columns as:
-
数字:用于接收标准数字。
¥Numbers: Use this for standard numbers.
-
文本:如果你预期输入的数字长度超过 16 位,请使用此选项。如果没有此设置,数字可能不正确。
¥Text: Use this if you expect numbers longer than 16 digits. Without this, numbers may be incorrect.
更新#
¥Update
使用此操作更新表格中的行。
¥Use this operation to update rows in a table.
请输入以下参数:
¥Enter these parameters:
- 用于连接的凭据:创建或选择现有 Postgres 凭据。
¥Credential to connect with: Create or select an existing Postgres credential.
- 操作:选择“更新”。
¥Operation: Select Update.
- 架构:请选择包含你要处理的表的架构。选择“从列表”从下拉列表中选择架构,或选择“按名称”输入架构名称。
¥Schema: Choose the schema that contains the table you want to work on. Select From list to choose the schema from the dropdown list or By Name to enter the schema name.
- 表:选择要处理的表格。选择“从列表”从下拉列表中选择表格,或选择“通过名称”输入表格名称。
¥Table: Choose the table that you want to work on. Select From list to choose the table from the dropdown list or By Name to enter the table name.
- 映射列模式:如何将列名映射到传入数据?
¥Mapping Column Mode: How to map column names to incoming data:
-
手动映射每一列:选择每列的值。
¥Map Each Column Manually: Select the values to use for each column.
-
自动映射:自动将传入数据映射到 Postgres 数据库中匹配的列名。为确保此功能正常工作,传入的数据字段名称必须与 Postgres 数据库中的列名称匹配。如有必要,请考虑在此节点前使用 编辑字段(设置)节点 来根据需要调整格式。
¥Map Automatically: Automatically map incoming data to matching column names in Postgres. The incoming data field names must match the column names in Postgres for this to work. If necessary, consider using the edit fields (set) node before this node to adjust the format as needed.
更新选项#
¥Update options
- 连接超时:尝试连接到数据库的秒数。
¥Connection Timeout: The number of seconds to try to connect to the database.
- 空闲连接关闭延迟:等待空闲连接直至将其关闭的秒数。
¥Delay Closing Idle Connection: The number of seconds to wait before considering idle connections eligible for closing.
- 查询批处理:向数据库发送查询的方式:
¥Query Batching: The way to send queries to the database:
-
单查询:针对所有传入项的单个查询。
¥Single Query: A single query for all incoming items.
-
独立:对执行的每个传入项执行一个查询。
¥Independently: Execute one query per incoming item of the execution.
-
事务:执行事务中的所有查询。如果发生故障,Postgres 会回滚所有更改。
¥Transaction: Execute all queries in a transaction. If a failure occurs, Postgres rolls back all changes.
-
输出列:选择要输出的列。你可以从可用列列表中选择,也可以使用 expressions 指定 ID。
¥Output Columns: Choose which columns to output. You can select from a list of available columns or specify IDs using expressions.
- 输出大格式数字:
NUMERIC和BIGINT列的输出格式:
¥Output Large-Format Numbers As: The format to output NUMERIC and BIGINT columns as:
-
数字:用于接收标准数字。
¥Numbers: Use this for standard numbers.
-
文本:如果你预期输入的数字长度超过 16 位,请使用此选项。如果没有此设置,数字可能不正确。
¥Text: Use this if you expect numbers longer than 16 digits. Without this, numbers may be incorrect.
-
将空字符串替换为 NULL:是否将输入中的空字符串替换为 NULL。处理从电子表格软件导出的数据时,此功能可能很有用。
¥Replace Empty Strings with NULL: Whether to replace empty strings with NULL in input. This may be useful when working with data exported from spreadsheet software.
模板和示例#
¥Templates and examples
相关资源#
¥Related resources
n8n 提供 Postgres 的触发节点。你可以找到触发节点文档 此处。
¥n8n provides a trigger node for Postgres. You can find the trigger node docs here.
使用查询参数#
¥Use query parameters
创建要在 Postgres 数据库上运行的查询时,你可以使用“选项”部分中的“查询参数”字段将数据加载到查询中。n8n 对查询参数中的数据进行清理,以防止 SQL 注入。
¥When creating a query to run on a Postgres database, you can use the Query Parameters field in the Options section to load data into the query. n8n sanitizes data in query parameters, which prevents SQL injection.
例如,你想要根据电子邮件地址查找某人。给定以下输入数据:
¥For example, you want to find a person by their email address. Given the following input data:
1 2 3 4 5 6 7 8 9 10 11 12 | |
你可以编写如下查询:
¥You can write a query like:
1 | |
然后在“查询参数”中,提供要使用的字段值。你可以提供固定值或表达式。在此示例中,请使用表达式,以便节点可以依次从每个输入项中提取电子邮件地址:
¥Then in Query Parameters, provide the field values to use. You can provide fixed values or expressions. For this example, use expressions so the node can pull the email address from each input item in turn:
1 2 | |
常见问题#
¥Common issues
有关常见问题或建议的解决方案,请参阅 常见问题。
¥For common questions or issues and suggested solutions, refer to Common issues.