1. Opening Problem Statement
Meet Sarah, a sales operations manager at a fast-growing SaaS company. Every day, her team receives updates on potential leads stored in their Postgres database. However, manually filtering out irrelevant contacts—like internal team members with @n8n.io emails—and exporting qualified leads into a Google Sheets file wastes hours each week. The manual process not only eats up Sarah’s time but often leads to outdated or inaccurate lead lists, causing missed follow-ups and lost revenue opportunities.
Sarah needs a reliable way to automatically sync and filter leads from Postgres into Google Sheets, ensuring her sales team always has the latest qualified leads ready for outreach, without the overhead of manual work.
2. What This Automation Does
This n8n workflow streamlines Sarah’s process by:
- Triggering updates from a Postgres database whenever user data changes.
- Filtering out users with @n8n.io email addresses to exclude internal contacts.
- Transforming raw database data into a format suited for sales outreach.
- Appending or updating qualified users in a designated Google Sheets document.
- Eliminating manual export/import operations to save significant time.
- Providing a manual test trigger and sample data node for workflow testing and development.
By automating these steps, Sarah saves hours weekly, minimizes errors, and keeps her lead information always up-to-date.
3. Prerequisites ⚙️
- Postgres database with access credentials 🔐
- Google Sheets account with OAuth2 credentials 📊
- n8n automation platform account (self-hosting optional)
- Basic understanding of how to use n8n nodes and connections
4. Step-by-Step Guide
Step 1: Configure the Postgres Trigger Node
Navigate to the Postgres Trigger node.
Set it to listen for UPDATE events on the users table within the computed schema.
Ensure you add your Postgres credentials named “Postgres Product Analytics.” This node will automatically trigger the workflow whenever user data is updated.
Visual: You should see a green “Enabled” status once triggered during actual deployment (disabled by default here).
Common mistake: Forgetting to enable the node means the workflow won’t trigger automatically.
Step 2: Add a Filter Node to Exclude Internal Emails
This node removes users with @n8n.io email addresses.
In the Filter node configuration, set the condition to filter out items where the email field contains n8n.io.
Visual: The node will show how many records passed the filter on execution.
Common mistake: Leaving the operation as “contains” instead of “notContains” results in reversed filtering.
Step 3: Connect a Manual Trigger and Mock Data Node
For testing your workflow without waiting for database events, use the Manual Trigger node named On clicking "Execute Node".
Connect this to a Code node containing example user data:
return [
{
"id": 1,
"username": "max_mustermann",
"email": "[email protected]",
"company_size": "500-999",
"role": "Sales",
"users": 50
}
]
This allows you to simulate the filtering and upload process manually.
Visual: You should see the mock user data flow into the filter during testing.
Step 4: Append or Update Google Sheets with Qualified Users
Configure the Google Sheets node to connect to your spreadsheet.
Select the document ID and the appropriate sheet (by GID).
Set the operation to appendOrUpdate with matching on the id column. Map the columns id, email, and username accordingly.
Visual: Once executed, the sheet should update with filtered user data.
Common mistake: Using incorrect document or sheet IDs will cause failed writes.
Step 5: Link the Nodes Correctly in the Workflow
Ensure connections flow as follows:
- Postgres Trigger or Manual Trigger → Filter
- Filter → Google Sheets
This setup processes either live database changes or manual tests through the filter and onto the sheet.
5. Customizations ✏️
1. Change Filter Criteria
Modify the Filter node to exclude other email domains by changing n8n.io to any string value.
2. Replace Google Sheets with CRM
You could swap the Google Sheets node for HubSpot or Pipedrive nodes to integrate lead data directly into your sales CRM.
3. Enable Real Postgres Triggers
Enable the Postgres Trigger node and ensure your Postgres DB supports triggers and event notifications properly.
6. Troubleshooting 🔧
Problem: “Workflow does not trigger on database update.”
Cause: Postgres Trigger node disabled or missing notification setup.
Solution: Enable the Postgres Trigger node and configure Postgres to send UPDATE notifications on the users table.
Problem: “Filtered results include internal emails.”
Cause: Filter node condition set incorrectly.
Solution: Verify filter condition uses “notContains” and the correct field email.
Problem: “Google Sheets update fails.”
Cause: Incorrect Google Sheets credentials or document ID.
Solution: Re-authenticate Google Sheets node and verify sheet ID and permissions.
7. Pre-Production Checklist ✅
- Verify Postgres trigger is enabled and test database update sends event.
- Run manual trigger with mock data and confirm filter removes internal emails.
- Check Google Sheets node mapping and permissions.
- Validate actual deployment execution updates Google Sheets accurately.
8. Deployment Guide
Activate the Postgres Trigger node and save your workflow.
Monitor executions in n8n’s UI to ensure updates flow correctly.
Consider logging success/failure in a custom dashboard if desired.
9. FAQs
Can I use a different database than Postgres?
Yes, but you’ll need to replace the Postgres Trigger node with a suitable database trigger node and adjust credentials accordingly.
Is my Google Sheets data secure?
Data is accessed via OAuth2 credentials and is as secure as your Google account permissions allow.
Can I add more filtering conditions?
Absolutely, add multiple conditions in the Filter node or use additional transformation nodes like Set or Code to customize data.
10. Conclusion
This tutorial showed how to automate syncing qualified user leads from a Postgres database into a Google Sheets document using n8n. You built an automated filter to exclude internal emails and keep your lead list fresh.
By removing manual exports and imports, this workflow can save you hours each week and reduce costly mistakes in your sales outreach.
Next, consider extending this automation to integrate directly with your CRM, add enriching data transformations, or alert sales reps via Slack when new leads appear.
Enjoy your newfound automation efficiency and keep innovating!