×

Streamline Database Reporting: n8n for SQL Automation

August 14, 2025

Back
Streamline Database Reporting: n8n for SQL Automation

For many organizations, SQL reporting can be a mundane task. Connecting to databases, executing queries, formatting tables, and emailing reports. There is nothing particularly complicated about these tasks, but they take up a lot of time that could have been spent uncovering insights and thinking strategically. In this blog, we will explore how to automate your SQL reporting workflows through n8n and create polished, scheduled email reports so that you can forget about repetitive work and instead focus on what matters: understanding data and making informed judgments.

Why Manual SQL Reporting Drains Time and Resources

In a lot of organizations, the routine is the same each week: connect to the database, run the same set of queries, format the results in a readable table, and send them to decision-makers.

There are no advanced models or machine learning needed for these tasks; while they are simple and easy, they are also taking your time.  And for data teams, that's less time for analysis, insights, and innovation.

In this blog, you'll learn how to turn a one-time setup into a recurring, fully automated email report that separates you from repetitive database work.

A Simple Four-Step Automated Reporting Setup

You can automate SQL reporting end-to-end into one combined visual flow with n8n, no more scripts, no more schedulers, no more emails. This process connects to your database, runs queries on a schedule, converts your results into an HTML table, and sends it directly to the recipients you specify.

The process is run with four nodes:

  • Schedule Trigger—Indicate the time for the workflow to run
  • PostgreSQL Node – Will pull the sales data directly from your database, running the query you specify.
  • Code Node—Formats the data into a clean, styled report in HTML.
  • Send Email Node—Sends the completed report to your chosen inbox/existing inboxes.

So, once this process is set up, you have the four-step flow to get your reports accurate and consistent.

The process is run with four nodes

Creating Your Workflow: A Step-by-Step Guide
To build up your n8n process, from database connection to automatic email distribution, simply follow these steps. Every step guarantees that your SQL reports function properly and are sent on schedule to the appropriate parties.

Step 1: Prepare Your PostgreSQL Database

To get going, let’s take Supabase, which is a cloud-hosted PostgreSQL service that only takes a couple of minutes to set up and manage. Alternatively, you could use other PostgreSQL solutions, such as AWS RDS, Google Cloud SQL, or your organization’s database.

Set up your database:

  • Sign up for a Supabase account and create a new project with any name and region.
  • Wait a few minutes while they provision your database.
  • Copy your connection details from Settings → Database for use later when we connect n8n.

Add Sample Data:

Supabase provides you with an SQL editor where you can create tables and add sample records for testing. This is wise because your automated report workflow will need some data to query when it runs.

Add Sample Data

Check the Setup:

Check the Setup

Run a quick test query, such as a count of rows in your employees table, to confirm everything is working. Once you see what you expect, your database setup is ready to be connected to the n8n workflow.

Step 2: Set Up Gmail for Automatic Email Delivery

You will need an App Password for n8n to send emails via Gmail:

1. Enable 2-Step Verification on your Google Account settings

2. Select Security → App Passwords

3. Select "Mail", and label it (e.g., n8n_reporting)

4. Copy the automatically generated 16-character password.

Step 3: Import and Customize the Workflow

Import the Workflow:

  • Download the workflow JSON file provided.
  • In n8n, select Import from File and name it "Automated SQL Reporting."

Connect to Your Database:

  • Open the PostgreSQL node.
  • Enter your Supabase credentials (host, database, user, password, port, enable SSL)
  • Test with your credentials to ensure n8n can access your data.

Configure Email Delivery:

  • Open the Send Email node.
  • Configure the SMTP using your Gmail address and app password.
  • Use smtp.gmail.com, port 587, and select STARTTLS for secure sending.
  • Once setup, you are ready to start querying the database and automate your reporting.

Configure Email Delivery

Step 4: Launch Your Workflow After Testing

After configuring your workflow, you can now run it manually in n8n, to test that everything works as expected. As the workflow runs, each node will turn green as it completes successfully. Inside your email inbox, check that you have received the desired HTML report. If you are satisfied with the result, you can turn on the workflow so that it is automatically executed according to the schedule, ensuring you get the reports when you need them reliably and without further action on your part.

Breaking Down Your Automated Report Output

Every time the workflow runs, it delivers a clean and concise report for decision makers to read. An email is sent with a subject like "Weekly Sales Report – [Date]", and in the body, it provides an HTML table with proper formatting.

The table includes individual employee sales, a summary of key statistics, correctly formatted currency, and the exact time it was sent for auditing. The workflow performs all the calculations of totals and averages from the SQL results, eliminating the need for manual formatting and adjustments.

Breaking Down Your Automated Report Output

How Each Node Powers the Workflow

How Each Node Powers the Workflow

Adapting Your Workflow for Different Needs

The standard workflow process can be easily adapted for all kinds of reporting applications. For example, you can easily change the query period to report monthly instead of weekly or filter to show data for a specific team or department.

Likewise, you can add any other number of metrics depending on your analysis objectives, such as product categories or regions. Being flexible means the workflow process can fundamentally remain the same whether you're developing a daily dashboard, a quarterly summary, or an ad hoc report for unique needs.

Moving Forward with Smarter Reporting

With n8n automating SQL workflows, repetitive reporting tasks become effortless, reducing errors and saving valuable time. By connecting PostgreSQL, Gmail, and n8n, you can deliver clean HTML reports directly to your inbox, keeping data timely and actionable.

In addition to automating workflows, it can be beneficial for data science professionals to also improve their intellect in a domain with accredited organizations such as the United States Data Science Institute (USDSI ® ). Programs like Certified Data Science Professional (CDSP™) and Certified Lead Data Scientist (CLDS™), paired with experiential skills, will provide you with a new understanding and potentially smarter decision-making systems and keep you current in the constantly evolving data science industry. 

By using more efficient tools and thought-out learning paths, you can not only improve your report-making process, but you will also invest in your knowledge, spending less time on reporting and more time on insight analysis.

This website uses cookies to enhance website functionalities and improve your online experience. By clicking Accept or continue browsing this website, you agree to our use of cookies as outlined in our privacy policy.

Accept