Use this sophisticated n8n workflow to sync Google Sheets data to PostgreSQL, then query the database naturally using a Gemini AI Agent. Leverage powerful n8n templates for RAG.
Download this n8n workflow template and start using it instantly.
This advanced solution leverages the power of n8n to bridge the gap between structured spreadsheet data and intelligent AI analysis. It provides a robust, two-part system. The first part is a data pipeline that automatically detects changes via a Google Drive n8n trigger, pulls Google Sheets data, dynamically infers data types (handling complex values like currency, percentages, and various date formats) using a custom n8n node, and loads it into PostgreSQL for reliable storage. The second part—the conversational interface—is an AI Agent that uses specialized n8n templates and LangChain tools (powered by Google Gemini) to generate and execute complex SQL queries based on natural language input. This full-cycle n8n workflow transforms static data into a dynamic, conversational knowledge base, providing deep data insights without requiring manual SQL coding.
This comprehensive n8n workflow consists of two major interconnected parts: Data Synchronization and AI Querying.
changethis Set n8n node defines the target tableurl and sheetname.aitable...) already exists.remove table Postgres n8n node to ensure a clean refresh.create table query Code n8n node performs crucial data type inference, detecting column types (Timestamp, Decimal for currency, Text) and generating a precise CREATE TABLE SQL query.create table PostgreSQL n8n node executes the schema creation.create insertion query Code n8n node iterates through the sheet data, normalizing values (e.g., stripping currency symbols, converting dates to ISO format), and building a highly optimized, parameterized INSERT INTO query.perform insertion PostgreSQL n8n node executes the bulk data load.AI Agent With SQL Query Prompt n8n node (LangChain Agent, powered by Google Gemini Chat Model) takes control.getpostgresschema tool (a separate n8n workflow) to understand the current database structure.executequery_tool (another separate n8n workflow) to run the generated SQL query against the database.To deploy this RAG n8n workflow, you must import this JSON and set up two additional sub-workflows for the AI tools, as indicated by the sticky notes.
A. queryexecuter Workflow
This workflow handles SQL execution.
The n8n trigger is Execute Workflow Trigger.
It connects to the sql query executor (Postgres n8n node, executing {{ $json.query.sql }}).
The result feeds into response output (Set n8n node) to return the data.
B. get database schema Workflow
This workflow retrieves schema information for the Agent.
The n8n trigger is Execute Workflow Trigger.
It connects to schema finder (Postgres n8n node, running the schema query).
The result is passed to schema to string (Code n8n node) to format the schema for the LLM.
Google Drive Trigger is watching the correct file ID.changethis n8n node with your spreadsheet URL and sheet name.queryexecuter and get database schema workflow IDs are correctly linked in the executequerytool and getpostgres_schema nodes respectively. Google Drive Trigger (n8n trigger): Starts the data synchronization process upon changes to a watched Google Sheet file.
Google Sheets (n8n node): Fetches all data rows from the specified sheet URL, preparing it for database migration.
Code Node (create table query): This highly customized n8n node analyzes sample data to infer data types, specifically identifying currency fields (e.g., '$', '₹') and date formats (MM/DD/YYYY). It generates the dynamic CREATE TABLE SQL command for PostgreSQL.
Code Node (create insertion query): Handles data cleansing and normalization. It converts messy spreadsheet data (like currency strings) into clean, ready-to-insert numeric or date values, generating a fast, parameterized INSERT INTO query.
Postgres (n8n node): Used throughout the n8n workflow for checking table existence, dropping tables, creating the new schema, and performing the bulk data insertion.
When chat message received (n8n trigger): The primary n8n trigger for the RAG component, starting the natural language query session.
Google Gemini Chat Model (LangChain n8n node): The large language model providing the reasoning capabilities for the agent to convert text into complex SQL.
AI Agent With SQL Query Prompt (LangChain n8n node): The core orchestration n8n node. It manages the conversation, utilizes the getpostgresschema and executequerytool n8n templates (via the tool workflow nodes) to gather information, construct the query, and deliver the final answer based on a detailed RAG prompt.
Deploy an advanced AI assistant using this n8n workflow. It combines Retrieval-Augmented Generation (RAG) via Supabase and Text-to-SQL via Peliqan to query internal documents and quantitative business data effectively. This n8n template accelerates BI.

Deploy a powerful n8n workflow using an AI agent, OpenAI, and Peliqan to transform natural language questions into accurate SQL queries against your Uniconta ERP data, leveraging Text-to-SQL technology.

Use this powerful n8n workflow to create an AI Agent capable of querying Cin7 ERP data via natural language. Integrates n8n nodes for Peliqan and OpenAI for Text-to-SQL automation.

Automate natural language queries for Monday.com tasks using this powerful n8n workflow. Integrate GPT-4o to analyze real-time board data instantly, eliminating manual searches.

Use this powerful n8n workflow template to query your MySQL database using plain English via an AI Agent powered by OpenAI. This n8n workflow integrates multiple n8n node types for advanced data access.

I combine my full-stack development expertise with AI automation using n8n, creating scalable workflows and seamless integrations for smarter business solutions.







































