Query Google Sheets/CSV data through an AI agent using PostgreSQL
Needs changesWhat this workflow does
This AI workflow has 20 nodes and runs on Manual Chat events (plus 2 other triggers). Along the way it connects Google Drive, Google Gemini Chat Model, Postgres and Google Sheets.
How it runs
Trigger: On Manual Chat events (plus 2 other triggers).
- AI Agent: runs an AI agent, with model: Google Gemini Chat Model; 2 tools (execute_query_tool, get_postgres_schema)
- sql query executor (Postgres): run a query
- schema finder (Postgres): run a query
- change_this (Edit Fields (Set)): sets 2 fields: table_url, sheet_name
- response output (Edit Fields (Set)): sets 1 field: response
- schema to string (Code): runs custom JavaScript code
- table exists? (Postgres): run a query
- fetch sheet data (Google Sheets): uses Google Sheets
- is not in database (If): checks a condition and branches into true / false
- create table query (Code): runs custom JavaScript code
…plus 4 more steps. See the full node list below.
Services it uses
Before you upgrade to n8n 3.0
2 things in this workflow are removed in n8n 3.0. Fix them before you upgrade:
- Manual Chat Trigger in When chat message received: replace with Chat Trigger.
- AI Agent v1 (old agent modes) in AI Agent With SQL Query Prompt (v1.7): replace with Latest AI Agent node (Tools Agent). For SQL Agent, use a Postgres or MySQL tool with a recent AI Agent.
Rather not rewrite it? Many of these flows can be rebuilt in Make (free plan).
| Removed in 3.0 | Replace with |
|---|---|
| Manual Chat Trigger When chat message received | Chat Trigger |
| AI Agent v1 (old agent modes) AI Agent With SQL Query Prompt (v1.7) | Latest AI Agent node (Tools Agent). For SQL Agent, use a Postgres or MySQL tool with a recent AI Agent. |
Nodes used (11)
- Code
n8n-nodes-base.code - Google Drive Trigger
n8n-nodes-base.googleDriveTrigger - Call n8n Workflow Tool
@n8n/n8n-nodes-langchain.toolWorkflow - Google Gemini Chat Model
@n8n/n8n-nodes-langchain.lmChatGoogleGemini - Edit Fields (Set)
n8n-nodes-base.set - If
n8n-nodes-base.if - Postgres
n8n-nodes-base.postgres - Google Sheets
n8n-nodes-base.googleSheets - Execute Workflow Trigger
n8n-nodes-base.executeWorkflowTrigger - Manual Chat Trigger
@n8n/n8n-nodes-langchain.manualChatTrigger - AI Agent
@n8n/n8n-nodes-langchain.agent
From the author
Want to see it in action? Watch the full breakdown here: 📺 Video Link Template Description This n8n workflow empowers you to query structured financial data from Google Sheets or CSV files using AI-generated SQL. Unlike traditional vector database solutions…