What This Workflow Does
This workflow connects Google Sheets and PostgreSQL to update product data automatically.
It stops manual exporting and fixing errors in dates or currency.
The result is clean data in PostgreSQL that you can ask questions about without writing SQL.
The workflow runs when sheet data changes.
The system checks if a table for the sheet exists.
If not, it makes one with the right column types.
It reads all sheet rows, cleans date and money formats, and loads the data.
Then, it lets you ask questions in plain language.
An AI builds SQL for the questions and shows answers fast.
Tools and Services Used
- n8n: Manages the automation workflow.
- Google Drive Trigger: Detects changes in Google Sheets.
- Google Sheets API: Reads data from spreadsheets.
- PostgreSQL: Stores and manages product data.
- Google PaLM API with Gemini Chat Model: Understands natural language queries.
- LangChain Agent: Builds SQL queries from user questions.
How This Workflow Works: Inputs, Process, Output
Inputs
- Google Sheets spreadsheet changes detected by Google Drive Trigger.
- Sheet URL and sheet name given in the Set node.
Processing Steps
- Check if the PostgreSQL table named after the sheet exists.
- If no table, the Code node builds a CREATE TABLE SQL statement with proper types by detecting dates and currency.
- Execute CREATE TABLE query if needed.
- Fetch sheet data via Google Sheets node.
- Normalize currencies, percentages, and date formats inside a Code node.
- Build a parameterized INSERT query for all rows.
- Insert cleansed data into PostgreSQL.
- Use LangChain Agent with Google Gemini Chat Model to receive user questions.
- Agent fetches schema, makes SQL from the question, runs the query, and formats the answer.
Output
- Updated PostgreSQL table with clean data ready for analysis.
- Real-time answers to natural language questions about the data.
Who Should Use This Workflow
This is for people who use Google Sheets to hold product or inventory data.
If manual exporting and cleaning to a database wastes time, this tool helps.
You need little coding skill but want fast data updates and easy questioning.
It fits companies worried about messy dates and money formats causing errors.
Beginner Step-by-Step: How to Use this Workflow in n8n
Step 1: Get the Workflow File
- Click the Download button on this page to get the workflow file.
- Open your n8n editor where you work on automations.
- Go to the menu and pick “Import from File”.
- Select the workflow file you just downloaded.
Step 2: Set Your Credentials
- Make sure Google Drive and Google Sheets credentials are added in n8n.
- Add your PostgreSQL credentials into n8n’s credential manager.
- Add your Google PaLM API key inside the Google Gemini Chat Model node.
Step 3: Configure IDs and Names
- Open the Set node named change_this.
- Put your correct Google Sheets file URL in
table_url. - Set the exact sheet tab name in
sheet_name. - If you have custom table naming, update the table names where needed.
Step 4: Test the Workflow
- Run the workflow manually once.
- Check the outputs in Google Sheets and PostgreSQL nodes.
- Make sure data is fetched and inserted properly.
Step 5: Activate for Production
- Switch the workflow ON by toggling the activate button.
- Let the Google Drive Trigger listen for real-time changes.
- Test the chat interface by asking data questions.
- If self hosting n8n, see self-host n8n for setup help.
Customization Ideas
- Change
sheet_nameandtable_urlin the Set node to use different sheets. - Add more currency symbols in the Code nodes for new money formats.
- Build logic to insert only changed rows instead of full refresh.
- Edit AI Agent system messages to change how answers look and feel.
- Adjust date matching regex for different formats if needed.
Troubleshooting Tips
- SQL errors near column names often mean spaces or special characters must be replaced with underscores in the Code nodes.
- Database connection fails? Check PostgreSQL credentials and try reconnecting.
- Date parsing errors usually happen when sheet dates differ from MM/DD/YYYY. Adjust code regex or format dates directly in Sheets.
Pre-Production Checklist
- Test Google Drive Trigger is firing when the right spreadsheet updates.
- Verify PostgreSQL login works and has proper rights.
- Preview sheet data rows correctly in Google Sheets node.
- Try a full table drop and recreate to see if CREATE TABLE query works.
- Insert sample data with currency and dates, check data correctness.
- Ask questions in AI chat, verify valid SQL queries and results.
- Save a backup copy before turning workflow live.
Deployment Guide
After testing, turn the workflow on with the enable switch inside n8n.
Ensure all credential nodes have connected keys and passwords.
Use the Google Drive Trigger for latest changes or schedule runs as preferred.
Watch execution logs in n8n to catch errors early.
If running on your own server, explore self-host n8n for full control.
Summary
✓ Automates loading Google Sheets product data into PostgreSQL.
✓ Fixes data type issues like dates and currency automatically.
✓ Lets users ask questions in plain English using AI chat.
✓ Saves hours weekly by removing manual exports and fixes.
✓ Makes querying databases simple without SQL knowledge.
