Synchronize Google Sheets with PostgreSQL
detail.loadingPreview
Automate the synchronization of data between Google Sheets and a PostgreSQL database.
About This Workflow
This workflow synchronizes data from a Google Sheet to a PostgreSQL database. It retrieves data from Google Sheets, compares it with existing data in PostgreSQL, and then inserts new records or updates existing ones based on the comparison.
Key Features
- Scheduled execution (hourly).
- Connects to Google Sheets and PostgreSQL.
- Compares datasets based on specified fields (e.g.,
first_name). - Supports inserting new records.
- Supports updating existing records.
- Splits out relevant fields for processing.
How To Use
Setup Instructions:
- Credentials: Ensure your Google Sheets and PostgreSQL credentials are set up in n8n.
- Google Sheets Node: Configure the
Retrieve Sheets Datanode with your specificdocumentIdandsheetName(orgid). - PostgreSQL Nodes: Configure the
Select Rows in Postgres,Insert Rows, andUpdate Rowsnodes with your PostgreSQL connection details, table (testing), and schema (public). - Field Mapping: In the
Split Out Relevant Fieldsnode, ensure thefieldToSplitOutparameter lists all the columns you wish to synchronize (e.g.,first_name, last_name, town, age). - Comparison Logic: In the
Compare Datasetsnode, define themergeByFieldsto specify how records should be matched between the Google Sheet data and PostgreSQL data. The example usesfirst_name. - Insert/Update Logic: The
Insert RowsandUpdate Rowsnodes handle the database operations. TheUpdate Rowsnode specifically usesfirst_nameandlast_nameas matching keys for updates, and thecolumnsparameter maps data from the input to the database fields. - Scheduling: The
Schedule Triggeris set to run hourly. Adjust this interval as needed.
Node Descriptions:
- Schedule Trigger: Initiates the workflow on a defined schedule.
- Retrieve Sheets Data: Fetches data from a specified Google Sheet.
- Split Out Relevant Fields: Extracts specific fields from the incoming data.
- Select Rows in Postgres: Retrieves existing data from the PostgreSQL table to be used for comparison.
- Compare Datasets: Compares data from Google Sheets with data from PostgreSQL.
- Insert Rows: Inserts new records into the PostgreSQL table if they are not found during comparison.
- Update Rows: Updates existing records in the PostgreSQL table if changes are detected during comparison.
Apps Used
Workflow JSON
{
"id": "5552a274-4fe7-48aa-b59d-b88f2cb3ec41",
"name": "Synchronize Google Sheets with PostgreSQL",
"nodes": 29,
"category": "Data Sync",
"status": "active",
"version": "1.0.0"
}Note: This is a sample preview. The full workflow JSON contains node configurations, credentials placeholders, and execution logic.
Get This Workflow
ID: 5552a274-4fe7...
About the Author
Free n8n Workflows Official
System Admin
The official repository for verified enterprise-grade workflows.
Statistics
Related Workflows
Discover more workflows you might like
Universal CSV to JSON API Converter
Effortlessly transform CSV data into structured JSON with this versatile n8n workflow. Integrate it into any application as a custom API endpoint, supporting various input methods including file uploads and raw text.
Automate Local Business Outreach with AI-Powered Yelp Scraper
This workflow automates the process of scraping local business details from Yelp using AI, then leverages that data to send personalized partnership proposals via Gmail. It's perfect for sales and marketing teams looking to streamline lead generation and outreach campaigns.
Automate Getty Images Editorial Search & CMS Integration
This n8n workflow automates searching for editorial images on Getty Images, extracts key details and embed codes, and prepares them for seamless integration into your Content Management System (CMS), streamlining your content creation process.