与数据对话:将文本转换为 SQL 查询和可视化曲线
高级
这是一个Engineering、Product、AI领域的自动化工作流,包含 36 个节点。主要使用 If、Set、Merge、Postgres、ConvertToFile 等节点,结合人工智能技术实现智能自动化。 与数据对话:将文本转换为 SQL 查询和可视化曲线
前置要求
- •PostgreSQL 数据库连接信息
- •OpenAI API Key
使用的节点 (36 个)
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
"id": "mLHcEKvtCu6m9nYi",
"meta": {
"instanceId": "1fc85153dfc4ea22a8172f0d7347fa9f591f71e2064dc331f7bdc1d7ee422e7a",
"templateCredsSetupCompleted": true
},
"name": "与数据对话:将文本转换为 SQL 查询和可视化曲线",
"tags": [
{
"id": "xSQPh84nO2kyMj3e",
"name": "Talk to data",
"createdAt": "2025-02-25T10:55:43.575Z",
"updatedAt": "2025-02-25T10:55:43.575Z"
}
],
"nodes": [
{
"id": "5207b91b-5a29-4786-93e2-c7ba4bd1d0f1",
"name": "窗口缓冲区内存",
"type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
"position": [
340,
360
],
"parameters": {},
"typeVersion": 1.2
},
{
"id": "8571a134-1a79-4858-aa22-82a037a3a5f8",
"name": "无操作,不执行任何动作",
"type": "n8n-nodes-base.noOp",
"position": [
1080,
460
],
"parameters": {},
"typeVersion": 1
},
{
"id": "967fd040-bb82-4e97-a979-b1e91ef54b8f",
"name": "在输出中添加表名",
"type": "n8n-nodes-base.set",
"position": [
-380,
-60
],
"parameters": {},
"typeVersion": 3.4
},
{
"id": "80d47d3e-476e-43fd-a021-609cdad537c8",
"name": "本地保存文件",
"type": "n8n-nodes-base.readWriteFile",
"position": [
-40,
-60
],
"parameters": {},
"typeVersion": 1
},
{
"id": "8e715321-38a3-4ba6-abac-efe2ad54a039",
"name": "从文件中提取数据",
"type": "n8n-nodes-base.extractFromFile",
"position": [
-360,
460
],
"parameters": {},
"typeVersion": 1
},
{
"id": "d0f9eb57-2226-4b4a-b7e7-b09074f5c410",
"name": "聊天触发器",
"type": "@n8n/n8n-nodes-langchain.chatTrigger",
"position": [
-860,
460
],
"webhookId": "c308dec7-655c-4b79-832e-991bd8ea891f",
"parameters": {},
"typeVersion": 1.1
},
{
"id": "b05e11f0-f957-4067-85fc-35bded780b59",
"name": "AI 代理",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
220,
140
],
"parameters": {},
"typeVersion": 1.6
},
{
"id": "f91029ec-27e5-4f1d-aec8-711ef5a7e0e4",
"name": "便签",
"type": "n8n-nodes-base.stickyNote",
"position": [
-940,
-340
],
"parameters": {
"content": "确保您的表名与实际知识库结构匹配"
},
"typeVersion": 1
},
{
"id": "95f41622-0ff4-4841-a83d-265864599f2f",
"name": "便签1",
"type": "n8n-nodes-base.stickyNote",
"position": [
-200,
-320
],
"parameters": {
"content": "确保您的表名与实际知识库结构匹配"
},
"typeVersion": 1
},
{
"id": "b12dbb8a-48fe-4627-b209-916191aef4e6",
"name": "点击\"测试工作流\"时",
"type": "n8n-nodes-base.manualTrigger",
"position": [
-900,
-60
],
"parameters": {},
"typeVersion": 1
},
{
"id": "3044a292-9596-40dd-96a5-caeed0204630",
"name": "便签2",
"type": "n8n-nodes-base.stickyNote",
"position": [
-940,
180
],
"parameters": {
"content": "确保您的表名与实际知识库结构匹配"
},
"typeVersion": 1
},
{
"id": "a6691f03-8688-4844-85be-b4344e9010bf",
"name": "便签3",
"type": "n8n-nodes-base.stickyNote",
"position": [
140,
-320
],
"parameters": {
"content": "确保您的表名与实际知识库结构匹配"
},
"typeVersion": 1
},
{
"id": "002bf810-5408-40a1-a05d-9bdcab64a14c",
"name": "合并架构数据和聊天输入",
"type": "n8n-nodes-base.set",
"position": [
-120,
460
],
"parameters": {},
"executeOnce": true,
"typeVersion": 3.4
},
{
"id": "64b73d55-e01a-4777-a07c-6fb047d22666",
"name": "从本地文件加载架构",
"type": "n8n-nodes-base.readWriteFile",
"position": [
-620,
460
],
"parameters": {},
"typeVersion": 1
},
{
"id": "c016cffe-669b-418f-818f-cb3692c7dcdb",
"name": "提取 SQL 查询",
"type": "n8n-nodes-base.set",
"position": [
680,
380
],
"parameters": {},
"typeVersion": 3.4
},
{
"id": "3a9d2623-751d-4b62-9fb7-68d5d9c8facf",
"name": "检查查询是否存在",
"type": "n8n-nodes-base.if",
"position": [
840,
380
],
"parameters": {},
"typeVersion": 2.2
},
{
"id": "552385b5-1086-419d-b0b8-f7fa2479c13f",
"name": "便签4",
"type": "n8n-nodes-base.stickyNote",
"position": [
660,
-60
],
"parameters": {
"content": "确保您的表名与实际知识库结构匹配"
},
"typeVersion": 1
},
{
"id": "4ea865a5-7988-4563-9d5a-a7f4a4f9c31f",
"name": "便签5",
"type": "n8n-nodes-base.stickyNote",
"position": [
660,
-60
],
"parameters": {
"content": "确保您的表名与实际知识库结构匹配"
},
"typeVersion": 1
},
{
"id": "0a25db4f-cc81-46f1-93cb-9e3d4028516d",
"name": "便签7",
"type": "n8n-nodes-base.stickyNote",
"position": [
340,
560
],
"parameters": {
"content": "确保您的表名与实际知识库结构匹配"
},
"typeVersion": 1
},
{
"id": "66492a65-1553-4286-80ea-d03e631a0995",
"name": "便签8",
"type": "n8n-nodes-base.stickyNote",
"position": [
1100,
-40
],
"parameters": {
"content": "确保您的表名与实际知识库结构匹配"
},
"typeVersion": 1
},
{
"id": "73839265-f77a-4856-b1fb-b2be7f6ebe27",
"name": "格式化查询结果",
"type": "n8n-nodes-base.set",
"position": [
1180,
180
],
"parameters": {},
"executeOnce": true,
"typeVersion": 3.4
},
{
"id": "e9220e4e-8bdc-48ed-b29b-a2fe124b8b72",
"name": "准备最终输出",
"type": "n8n-nodes-base.set",
"position": [
2140,
580
],
"parameters": {},
"typeVersion": 3.4
},
{
"id": "81a292e1-c5e9-40df-a181-66f767c60215",
"name": "合并查询结果和聊天回答",
"type": "n8n-nodes-base.merge",
"position": [
1880,
580
],
"parameters": {},
"typeVersion": 3
},
{
"id": "4a35ebb4-37cb-4a7c-b005-70315c6f684c",
"name": "列出数据库中所有表",
"type": "n8n-nodes-base.postgres",
"position": [
-740,
-60
],
"parameters": {},
"typeVersion": 2.5
},
{
"id": "22da4137-af07-4c03-9c2d-6b8178571ff4",
"name": "将数据转换为 JSON",
"type": "n8n-nodes-base.convertToFile",
"position": [
-200,
-60
],
"parameters": {},
"typeVersion": 1.1
},
{
"id": "0d7d1e90-224b-4159-8930-4470b140305d",
"name": "模式提取器",
"type": "n8n-nodes-base.postgres",
"position": [
-560,
-60
],
"parameters": {},
"typeVersion": 2.5
},
{
"id": "ddba033b-aca0-42a0-b553-3edf4d93cd1f",
"name": "最终 SQL 结果",
"type": "n8n-nodes-base.postgres",
"position": [
1000,
180
],
"parameters": {},
"typeVersion": 2.5
},
{
"id": "3c2b1a0d-4a50-44b2-ada9-00d3b23b3c61",
"name": "编辑字段",
"type": "n8n-nodes-base.set",
"position": [
1440,
180
],
"parameters": {},
"typeVersion": 3.4
},
{
"id": "4ad38866-185e-4cd3-b0b0-b1e744d52204",
"name": "多表:您可以连接多个表以实现有组织的数据结构",
"type": "@n8n/n8n-nodes-langchain.outputParserStructured",
"position": [
1900,
420
],
"parameters": {},
"typeVersion": 1.2
},
{
"id": "744b6680-310b-4a89-a84c-dc59145fe73f",
"name": "编辑字段1",
"type": "n8n-nodes-base.set",
"position": [
2120,
180
],
"parameters": {},
"typeVersion": 3.4
},
{
"id": "196473ba-78c5-412c-8940-121a0e1f28d2",
"name": "绘图代理",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
1700,
180
],
"parameters": {},
"typeVersion": 1.7
},
{
"id": "9e03e081-0de2-4b8e-bcaa-adc0d2240272",
"name": "deepseek-chat",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"position": [
1700,
380
],
"parameters": {},
"typeVersion": 1.2
},
{
"id": "376d0712-00c4-4132-a429-b36234e75316",
"name": "Deepseek-chat",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"position": [
200,
360
],
"parameters": {},
"typeVersion": 1.2
},
{
"id": "43d27038-22c0-41ec-b2b5-507c311b23f1",
"name": "便签9",
"type": "n8n-nodes-base.stickyNote",
"position": [
1600,
-60
],
"parameters": {
"content": "确保您的表名与实际知识库结构匹配"
},
"typeVersion": 1
},
{
"id": "c206c591-5826-4285-900a-c082587bfbaa",
"name": "便签 10",
"type": "n8n-nodes-base.stickyNote",
"position": [
1600,
-40
],
"parameters": {
"content": "确保您的表名与实际知识库结构匹配"
},
"typeVersion": 1
},
{
"id": "57bbe158-4ddc-4f46-b871-d22735e3f720",
"name": "便签 11",
"type": "n8n-nodes-base.stickyNote",
"position": [
1260,
580
],
"parameters": {
"content": "确保您的表名与实际知识库结构匹配"
},
"typeVersion": 1
}
],
"active": false,
"pinData": {},
"settings": {
"executionOrder": "v1"
},
"versionId": "93ee6099-65dc-47bc-ba35-15f2e22b1412",
"connections": {
"AI Agent": {
"main": [
[
{
"node": "Extract SQL query",
"type": "main",
"index": 0
}
]
]
},
"plot agent": {
"main": [
[
{
"node": "Edit Fields1",
"type": "main",
"index": 0
}
]
]
},
"Edit Fields": {
"main": [
[
{
"node": "plot agent",
"type": "main",
"index": 0
}
]
]
},
"Chat Trigger": {
"main": [
[
{
"node": "Load the schema from the local file",
"type": "main",
"index": 0
}
]
]
},
"Edit Fields1": {
"main": [
[
{
"node": "Combine query result and chat answer",
"type": "main",
"index": 2
}
]
]
},
"Deepseek-chat": {
"ai_languageModel": [
[
{
"node": "AI Agent",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"deepseek-chat": {
"ai_languageModel": [
[
{
"node": "plot agent",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Final SQL result": {
"main": [
[
{
"node": "Format query results",
"type": "main",
"index": 0
}
]
]
},
"Schema Extractor": {
"main": [
[
{
"node": "Add table name to output",
"type": "main",
"index": 0
}
]
]
},
"Extract SQL query": {
"main": [
[
{
"node": "Check if query exists",
"type": "main",
"index": 0
}
]
]
},
"Convert data to Json": {
"main": [
[
{
"node": "Save file locally",
"type": "main",
"index": 0
}
]
]
},
"Format query results": {
"main": [
[
{
"node": "Combine query result and chat answer",
"type": "main",
"index": 0
},
{
"node": "Edit Fields",
"type": "main",
"index": 0
}
]
]
},
"Window Buffer Memory": {
"ai_memory": [
[
{
"node": "AI Agent",
"type": "ai_memory",
"index": 0
}
]
]
},
"Check if query exists": {
"main": [
[
{
"node": "Combine query result and chat answer",
"type": "main",
"index": 1
},
{
"node": "Final SQL result",
"type": "main",
"index": 0
}
],
[
{
"node": "No Operation, do nothing",
"type": "main",
"index": 0
}
]
]
},
"Extract data from file": {
"main": [
[
{
"node": "Combine schema data and chat input",
"type": "main",
"index": 0
}
]
]
},
"Add table name to output": {
"main": [
[
{
"node": "Convert data to Json",
"type": "main",
"index": 0
}
]
]
},
"Structured Output Parser": {
"ai_outputParser": [
[
{
"node": "plot agent",
"type": "ai_outputParser",
"index": 0
}
]
]
},
"List all tables in a database": {
"main": [
[
{
"node": "Schema Extractor",
"type": "main",
"index": 0
}
]
]
},
"When clicking \"Test workflow\"": {
"main": [
[
{
"node": "List all tables in a database",
"type": "main",
"index": 0
}
]
]
},
"Combine schema data and chat input": {
"main": [
[
{
"node": "AI Agent",
"type": "main",
"index": 0
}
]
]
},
"Load the schema from the local file": {
"main": [
[
{
"node": "Extract data from file",
"type": "main",
"index": 0
}
]
]
},
"Combine query result and chat answer": {
"main": [
[
{
"node": "Prepare final output",
"type": "main",
"index": 0
}
]
]
}
}
}常见问题
如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
这是一个高级难度的工作流,适用于Engineering、Product、AI等场景。适合高级用户,包含 16+ 个节点的复杂工作流
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
仅从数据库架构生成 SQL 查询 - AI 驱动
仅从数据库架构生成 SQL 查询 - AI 驱动
If
Set
Merge
+11
29 节点Yulia
Engineering
使用正则表达式和 AI 发现隐藏的网站 API 端点
使用正则表达式和人工智能发现隐藏的网站API端点
If
Set
Html
+19
58 节点Yulia
Engineering
在可视化参考库中探索n8n节点
在可视化参考库中探索n8n节点
If
Ftp
Set
+93
113 节点I versus AI
Other
与Supabase存储中文件对话的AI智能体
与Supabase存储中文件对话的AI智能体
If
Merge
Switch
+15
33 节点Mark Shcherbakov
Engineering
将邮件相关提问转换为SQL查询并执行
邮件助手:使用Phi4-mini和PostgreSQL将自然语言转换为SQL查询
If
Set
Merge
+10
26 节点Alfonso Corretti
Building Blocks
宠物店 4
🐶 宠物店预约 AI 代理
If
Set
Code
+41
187 节点Bruno Dias
AI