Skip to content
AI Agents

Convert Email Questions into Database Queries and Execute Them

23 nodes 625 219 Automatic trigger
Download

Loading workflow…

Workflow Description

An intelligent automation that accepts natural language questions about emails, converts them into SQL queries using a local language model, executes them against a PostgreSQL database, and returns results immediately to the user.

How it works

  1. 1.Receive the question through the interactive chat interface
  2. 2.Transform the natural language question into SQL using Ollama language model
  3. 3.Execute the query on the database and retrieve results
  4. 4.Display the answer and log the exchange to a file

Use cases

  • Answer analytical questions about emails without writing SQL code
  • Automate searching and filtering email archives using natural language
  • Build an intelligent assistant that understands user email intent

Requirements

  • PostgreSQL database containing email message tables
  • Local language model installed via Ollama or compatible LLM server
  • Read and write permissions on the file system

Service Value

Ready-made workflow template for automation delivery and service execution.

Apps Used

Set Convert To File Read Write File Twitter/X Chat Trigger Manual Trigger If Merge Postgres Lm Chat Ollama AI Agent

Details

Trigger Automatic trigger
Nodes 23
Apps 11
Views 625
Downloads 219

How to Use

  1. 1.Click "Download Template"
  2. 2.Open your n8n dashboard
  3. 3.Go to Workflows > Import from File
  4. 4.Select downloaded file and configure credentials

Nodes Used (23)

/

Add table name to output

Set

#1

Convert data to binary

Convert To File

#2

Save file locally

Read Write File

#3

Extract data from file

Extract From File

#4

Chat Trigger

Chat Trigger

#5

Sticky Note

Sticky Note

#6

When clicking "Test workflow"

Manual Trigger

#7

Combine schema data and chat input

Set

#8

Load the schema from the local file

Read Write File

#9

Extract SQL query

Set

#10

Check if query exists

If

#11

Format query results

Set

#12

Combine query result and chat answer

Merge

#13

List all columns in a table

Postgres

#14

List all tables in a database

Postgres

#15

Ollama Chat Model

Lm Chat Ollama

#16

Postgres

Postgres

#17

Add trailing semicolon

Set

#18

Check for trailing semicolon

If

#19

WorkflowTrigger

Execute Workflow Trigger

#20

If ran manually

If

#21

If file exists or already retried generating it

If

#22

Sticky Note1

Sticky Note

#23

AI Agent

Agent

#24

Format empty output

Set

#25

Sticky Note2

Sticky Note

#26
Stay in the loop

Fresh workflows, straight to your inbox

Get newly published DROPIDEA workflows, a clear overview of what they do, and a link to explore them.

  • New workflows
  • Clear overviews
  • Setup guides

Be first to discover what is new

Your name, your email, and one confirmation.

Email confirmation · Unsubscribe anytime