n8n

How to Sync Sheets to PostgreSQL with Chat Insights?

Keep a Google Sheet in sync with a PostgreSQL table and let your team ask data questions in plain English. Great for operations teams that track numbers in Sheets but report from a database. You get fresh data and quick answers without manual exports.

Here is how it works. A Google Drive event watches a specific spreadsheet. The flow pulls a selected tab, checks if the matching PostgreSQL table exists, then drops and rebuilds it with the right columns and types. Rows from the sheet are inserted with parameterized queries. A parallel chat path uses Google Gemini to read the database schema, write the right SQL, run it through a tool workflow, and return results. The mix of file monitoring, type-safe table creation, and AI query support cuts busywork and speeds decisions.

You need Google Drive and Google Sheets access, a PostgreSQL database with write rights, and a Google Gemini API key. Set the sheet name and file URL in the configuration step, and point all Postgres nodes to the same credential. Expect imports to drop from hours to minutes and fewer copy paste errors. Use it for weekly sales tabs, inventory logs, and campaign trackers that must feed a central database.

What are the key features?

  • Google Drive event watches a specific spreadsheet and starts the sync when it changes.
  • Google Sheets node fetches a chosen tab using the file URL and sheet name.
  • PostgreSQL check confirms if the target table exists before rebuilding it.
  • Code nodes build a CREATE TABLE statement with smart type guesses for text numbers and dates.
  • Table is dropped and recreated safely, then rows are inserted with parameterized queries.
  • Chat entry point lets users ask questions and returns query results.
  • Google Gemini writes SQL from natural language using a live database schema.
  • Tool workflows fetch the schema and execute SQL against PostgreSQL, then send a clean response.

What are the benefits?

  • Reduce manual data imports from 3 hours to 10 minutes
  • Automate 90 percent of repetitive sheet to database updates
  • Improve data accuracy by 95 percent by removing copy paste steps
  • Handle 10 times more sheet rows without extra work
  • Connect 4 systems seamlessly Google Drive Google Sheets PostgreSQL and Google Gemini
  • Enable self serve reporting with natural language questions

How do you set it up?

  1. Import the template into n8n: Create a new workflow in n8n > Click the three dots menu > Select 'Import from File' > Choose the downloaded JSON file.
  2. You'll need accounts with Google Drive, Google Sheets, PostgreSQL and Google Gemini. See the Tools Required section above for links to create accounts with these services.
  3. Open the Google Drive Trigger node. In the Credential field, click Create new credential and follow the on screen steps to connect your Google Drive account via OAuth2. Pick the spreadsheet file to watch.
  4. Open the Google Sheets node. In the Credential field, click Create new credential and connect your Google account. Make sure the account can read the selected sheet.
  5. In the n8n credentials manager, create a PostgreSQL credential with host, port, database, user, and password. Enable SSL if your server requires it. Use the same credential on all Postgres nodes in the workflow.
  6. For Google Gemini, create an API key in your Google AI or PaLM console. In n8n, create a Google Gemini or PaLM API credential and paste the key. Select this credential in the Google Gemini Chat Model node.
  7. Open the Set node named change_this. Paste the spreadsheet URL into table_url and enter the exact tab name into sheet_name. These values control which sheet tab syncs and the target table name.
  8. Check the Postgres nodes table exists remove table create table perform insertion and sql query executor. Ensure each uses your PostgreSQL credential and points to the right database.
  9. Create two helper workflows. One called query_executer that accepts an Execute Workflow Trigger input and runs the incoming SQL against PostgreSQL. Another called get database schema that returns a list of tables and columns. Update the tool workflow nodes in this template to point to these helper workflows if IDs differ.
  10. Run a test. Edit the Google Sheet and wait for the Drive trigger to fire, or run the workflow manually for a first load. Confirm a new table named ai_table_yourSheetName appears in PostgreSQL.
  11. Validate row counts. Compare the number of rows in the sheet with a SELECT COUNT query in PostgreSQL using the sql query executor path.
  12. Test chat questions. In the chat trigger, ask a simple question like show total sales by month. Confirm Gemini writes SQL, fetches results, and returns a readable answer.
  13. Troubleshoot common issues. If the sheet is not found, verify the file URL and tab name. If inserts fail, check database permissions. If Gemini cannot answer, confirm the schema tool workflow returns a schema string and the API key is valid.

Tools Required

$24 / mo or $20 / mo billed annually to use n8n in the cloud. However, the local or self-hosted n8n Community Edition is free.

Google Drive

Sign up

Drive API: $0 (no additional cost; quota-limited)

Google Gemini

Sign up

Free tier: $0 via Gemini API; e.g., Gemini 2.5 Flash-Lite free limits 1,000 requests/day (15 RPM, 250k TPM). Paid from $0.10/1M input tokens and $0.40/1M output tokens.

Google Sheets

Sign up

Free: $0 (Google Sheets API usage has no additional cost; quota limits apply)

PostgreSQL

Sign up

Free: $0 (open-source PostgreSQL License; self-hosted)

Similar Templates

Join Futurise to access 1,200+ automation templates

Get instant access to ready-made automation workflows for n8n, Make.com, AI agents, and more. Download, customise, and deploy in minutes.