Automate SQL Query Creation with OpenAI and Memory Buffer Window

Transform unstructured text into SQL queries seamlessly using an automated workflow powered by OpenAI GPT and the memory Buffer Window. This automation solves the common issue of manually converting data into actionable SQL commands, significantly reducing time and effort. Features include real-time data extraction from files, efficient memory management for enhanced conversation context, and seamless integration with various data sources. Perfect for data analysts and database administrators managing large volumes of data queries. Requires 0 accounts: simply set up your n8n environment and start automating. Save up to 80% of your query creation time and ensure error-free SQL generation.

Chat Trigger
3,073 views36 nodesApr 2025Sophia Brown

Categories

EngineeringAI Chatbot

AI Features

AI AgentOpenAI GPTAI Chat

Quick Actions

Copy or download to import into your n8n instance

Workflow JSON
{
  "id": "mLHcEKvtCu6m9nYi",
  "meta": {
    "instanceId": "1fc85153dfc4ea22a8172f0d7347fa9f591f71e2064dc331f7bdc1d7ee422e7a",
    "templateCredsSetupCompleted": true
  },
  "name": "Conversing with Data: Transforming Text into SQL Queries and Visual Curves",
  "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": "Window Buffer Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        340,
        360
      ],
      "parameters": {},
      "typeVersion": 1.2
    },
    {
      "id": "8571a134-1a79-4858-aa22-82a037a3a5f8",
      "name": "No Operation, do nothing",
      "type": "n8n-nodes-base.noOp",
      "position": [
        1080,
        460
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "967fd040-bb82-4e97-a979-b1e91ef54b8f",
      "name": "Add table name to output",
      "type": "n8n-nodes-base.set",
      "position": [
        -380,
        -60
      ],
      "parameters": {},
      "typeVersion": 3.4
    },
    {
      "id": "80d47d3e-476e-43fd-a021-609cdad537c8",
      "name": "Save file locally",
      "type": "n8n-nodes-base.readWriteFile",
      "position": [
        -40,
        -60
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "8e715321-38a3-4ba6-abac-efe2ad54a039",
      "name": "Extract data from file",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        -360,
        460
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "d0f9eb57-2226-4b4a-b7e7-b09074f5c410",
      "name": "Chat Trigger",
      "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 Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        220,
        140
      ],
      "parameters": {},
      "typeVersion": 1.6
    },
    {
      "id": "f91029ec-27e5-4f1d-aec8-711ef5a7e0e4",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -940,
        -340
      ],
      "parameters": {
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "95f41622-0ff4-4841-a83d-265864599f2f",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -200,
        -320
      ],
      "parameters": {
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "b12dbb8a-48fe-4627-b209-916191aef4e6",
      "name": "When clicking \"Test workflow\"",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -900,
        -60
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "3044a292-9596-40dd-96a5-caeed0204630",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -940,
        180
      ],
      "parameters": {
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "a6691f03-8688-4844-85be-b4344e9010bf",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        140,
        -320
      ],
      "parameters": {
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "002bf810-5408-40a1-a05d-9bdcab64a14c",
      "name": "Combine schema data and chat input",
      "type": "n8n-nodes-base.set",
      "position": [
        -120,
        460
      ],
      "parameters": {},
      "executeOnce": true,
      "typeVersion": 3.4
    },
    {
      "id": "64b73d55-e01a-4777-a07c-6fb047d22666",
      "name": "Load the schema from the local file",
      "type": "n8n-nodes-base.readWriteFile",
      "position": [
        -620,
        460
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "c016cffe-669b-418f-818f-cb3692c7dcdb",
      "name": "Extract SQL query",
      "type": "n8n-nodes-base.set",
      "position": [
        680,
        380
      ],
      "parameters": {},
      "typeVersion": 3.4
    },
    {
      "id": "3a9d2623-751d-4b62-9fb7-68d5d9c8facf",
      "name": "Check if query exists",
      "type": "n8n-nodes-base.if",
      "position": [
        840,
        380
      ],
      "parameters": {},
      "typeVersion": 2.2
    },
    {
      "id": "552385b5-1086-419d-b0b8-f7fa2479c13f",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        660,
        -60
      ],
      "parameters": {
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "4ea865a5-7988-4563-9d5a-a7f4a4f9c31f",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        660,
        -60
      ],
      "parameters": {
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "0a25db4f-cc81-46f1-93cb-9e3d4028516d",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        340,
        560
      ],
      "parameters": {
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "66492a65-1553-4286-80ea-d03e631a0995",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1100,
        -40
      ],
      "parameters": {
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "73839265-f77a-4856-b1fb-b2be7f6ebe27",
      "name": "Format query results",
      "type": "n8n-nodes-base.set",
      "position": [
        1180,
        180
      ],
      "parameters": {},
      "executeOnce": true,
      "typeVersion": 3.4
    },
    {
      "id": "e9220e4e-8bdc-48ed-b29b-a2fe124b8b72",
      "name": "Prepare final output",
      "type": "n8n-nodes-base.set",
      "position": [
        2140,
        580
      ],
      "parameters": {},
      "typeVersion": 3.4
    },
    {
      "id": "81a292e1-c5e9-40df-a181-66f767c60215",
      "name": "Combine query result and chat answer",
      "type": "n8n-nodes-base.merge",
      "position": [
        1880,
        580
      ],
      "parameters": {},
      "typeVersion": 3
    },
    {
      "id": "4a35ebb4-37cb-4a7c-b005-70315c6f684c",
      "name": "List all tables in a database",
      "type": "n8n-nodes-base.postgres",
      "position": [
        -740,
        -60
      ],
      "parameters": {},
      "typeVersion": 2.5
    },
    {
      "id": "22da4137-af07-4c03-9c2d-6b8178571ff4",
      "name": "Convert data to Json",
      "type": "n8n-nodes-base.convertToFile",
      "position": [
        -200,
        -60
      ],
      "parameters": {},
      "typeVersion": 1.1
    },
    {
      "id": "0d7d1e90-224b-4159-8930-4470b140305d",
      "name": "Schema Extractor",
      "type": "n8n-nodes-base.postgres",
      "position": [
        -560,
        -60
      ],
      "parameters": {},
      "typeVersion": 2.5
    },
    {
      "id": "ddba033b-aca0-42a0-b553-3edf4d93cd1f",
      "name": "Final SQL result",
      "type": "n8n-nodes-base.postgres",
      "position": [
        1000,
        180
      ],
      "parameters": {},
      "typeVersion": 2.5
    },
    {
      "id": "3c2b1a0d-4a50-44b2-ada9-00d3b23b3c61",
      "name": "Edit Fields",
      "type": "n8n-nodes-base.set",
      "position": [
        1440,
        180
      ],
      "parameters": {},
      "typeVersion": 3.4
    },
    {
      "id": "4ad38866-185e-4cd3-b0b0-b1e744d52204",
      "name": "Structured Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        1900,
        420
      ],
      "parameters": {},
      "typeVersion": 1.2
    },
    {
      "id": "744b6680-310b-4a89-a84c-dc59145fe73f",
      "name": "Edit Fields1",
      "type": "n8n-nodes-base.set",
      "position": [
        2120,
        180
      ],
      "parameters": {},
      "typeVersion": 3.4
    },
    {
      "id": "196473ba-78c5-412c-8940-121a0e1f28d2",
      "name": "plot agent",
      "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": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1600,
        -60
      ],
      "parameters": {
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "c206c591-5826-4285-900a-c082587bfbaa",
      "name": "Sticky Note10",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1600,
        -40
      ],
      "parameters": {
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "57bbe158-4ddc-4f46-b871-d22735e3f720",
      "name": "Sticky Note11",
      "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
          }
        ]
      ]
    }
  }
}

Related Workflows

Automate Customer Queries with OpenAI GPT & Serp API Integration

Automate customer queries with an AI assistant powered by OpenAI GPT and Serp API. Use the chat Trigger and memory Buffer Window to provide instant and accurate responses to customer inquiries 24/7. Features include conversation memory for seamless interactions, real-time data processing for updated answers, and automatic filtering to prioritize urgent messages. Perfect for e-commerce businesses handling over 100 daily product inquiries, SaaS support teams, or any customer-facing role that requires fast, reliable answers. Requires 2 accounts: OpenAI API and Serp API. Save up to 5 hours daily by managing unlimited customer conversations with contextual, product-specific answers from your resources.

966,031 views
Personal ProductivityAI Chatbot

Automate WhatsApp Customer Inquiries with OpenAI and Vector Storage

Automate customer inquiries on WhatsApp using an AI assistant powered by OpenAI GPT. By integrating WhatsApp Business API, this workflow enables your AI to respond to customer questions 24/7, enhancing user experience and engagement. Features conversation memory for seamless interactions, vector storage for precise answers, and automatic message processing for real-time responses. Perfect for e-commerce stores with over 50 daily inquiries, SaaS customer success teams, or sales departments requiring instant product information. Requires 3 accounts: WhatsApp Trigger API, OpenAI API, and WhatsApp Business API. Handle unlimited inquiries efficiently, saving up to 5 hours daily with contextual, accurate responses from your product documentation.

378,461 views
Lead NurturingAI Chatbot

Automate Customer Support with Chat Trigger and OpenAI GPT

Automate customer inquiries on your website using a chat trigger and an AI agent powered by OpenAI GPT. This workflow allows you to set up an AI chat that responds instantly to customer questions, ensuring 24/7 support without human intervention. Features conversation memory for context-aware interactions, automatic message processing to reduce response times, and seamless integration with your existing systems. Ideal for e-commerce platforms receiving 50+ inquiries daily or SaaS businesses needing efficient customer interaction. Requires 1 account: OpenAI API. Save up to 5 hours a day while handling unlimited inquiries with accurate, AI-generated responses.

244,872 views
EngineeringAI Chatbot

Automate RSS Feed Updates with Google Gemini and AI Agent

Streamline your RSS feed updates using Google Gemini and AI Agent for real-time content delivery. This automation workflow connects your RSS Feed Read Tool with the HTTP Request Tool, ensuring you receive instant updates on critical information. Features include conversation memory for personalized interactions, intelligent data processing via Google Gemini, and a memory buffer window for efficient handling of requests. Ideal for developers and integrators managing multiple content streams or building news aggregation tools. Requires 0 accounts: simply set up your RSS feeds. Experience a 90% reduction in manual update time and handle thousands of feed entries seamlessly.

214,164 views
Personal ProductivityAI Chatbot

How to Use This Workflow

1Import to n8n

  1. Copy the JSON using the button above
  2. Open your n8n instance
  3. Click “Import workflow” or press Ctrl+V
  4. Paste the JSON and click “Import”

2Before Running

Configure credentials and update service-specific settings before executing the workflow. Review required credentials in the Technical Details section above.

3.1K