Templates / Query Google Sheets/CSV data through an AI agent using PostgreSQL

Query Google Sheets/CSV data through an AI agent using PostgreSQL

Needs changes

by Leonardo Grigorio ✓ · 10,499 views · created 2025-03-04 · Document Extraction, AI RAG

Needs changes. This template uses 2 thing(s) that n8n 3.0 removes: Manual Chat Trigger, AI Agent v1 (old agent modes). 2 breaking item(s) found. Static check, last run 2026-10-19.

What 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).

  1. AI Agent: runs an AI agent, with model: Google Gemini Chat Model; 2 tools (execute_query_tool, get_postgres_schema)
  2. sql query executor (Postgres): run a query
  3. schema finder (Postgres): run a query
  4. change_this (Edit Fields (Set)): sets 2 fields: table_url, sheet_name
  5. response output (Edit Fields (Set)): sets 1 field: response
  6. schema to string (Code): runs custom JavaScript code
  7. table exists? (Postgres): run a query
  8. fetch sheet data (Google Sheets): uses Google Sheets
  9. is not in database (If): checks a condition and branches into true / false
  10. create table query (Code): runs custom JavaScript code

…plus 4 more steps. See the full node list below.

Services it uses

Google DriveGoogle Gemini Chat ModelPostgresGoogle Sheets

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.0Replace 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)

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…

Excerpt from Leonardo Grigorio's description on n8n.io.

View the original on n8n.io → Check your own copy

Get the weekly “what broke” email

New templates, newly broken ones, and n8n release changes. One short email a week.

Form not loading? Subscribe here.