Description
π€ Query Your Database with GPT-4o Using Natural Language
Automated SQL query generation and execution using AI β no manual SQL writing needed!
π Stop struggling with writing SQL β this workflow lets you ask plain-English questions and get instant SQL queries executed on your database via GPT-4o.
π§ What Problem Does It Solve?
Writing, debugging, and running SQL queries can be slow and technical, especially for non-experts. This workflow automates query generation and execution using GPT-4o and allows you to interact with your database conversationally.
π¬ Ask questions like:
-
βWhat tables are available?β
-
βAdd a new user named Harsh with email harsh@example.comβ
-
βShow the total sales for the last 30 daysβ
βοΈ How It Works
π¬ Listens for incoming chat messages
π€ Sends your question to GPT-4o with a smart SQL prompt
π GPT-4o responds with a valid, executable SQL query
π Executes the SQL query in a Postgres database
π₯ Returns the results or confirmation to your chat
β¨ Key Features
β
Uses GPT-4o to convert natural language to SQL
β
Supports PostgreSQL (can be swapped with MySQL or SQLite)
β
Automatically runs queries and fetches results
β
Built-in safeguards to avoid dangerous queries
β
Memory buffer for conversational context
β
Works with n8n embedded chat (or can be integrated with Slack, WhatsApp, etc.)
π§° What You Need
β
OpenAI API key (GPT-4o access)
β
Access to your Postgres, MySQL, or SQLite database
β
n8n version 1.19.4 or later
(Optional) Chat service integration (Slack, MS Teams, WhatsApp)
π Setup Instructions
-
π Connect your chat service or use n8n embedded chat
-
π Add credentials for OpenAI and your database
-
π§ Customize the AI prompt for your database schema if needed
-
π§ͺ Test with simple queries like βWhat tables exist?β
-
π§© Optionally extend to support updates, deletes, or analytics
π Integrations
-
OpenAI GPT-4o
-
PostgreSQL (MySQL / SQLite optional)
-
n8n Chat Interface (or Slack/MS Teams)
Project Link:-[https://preview--gpt-sql-converser.lovable.app/]