AI Agents

Query PostgreSQL Database Through Natural Language Chat

11 nodes 323 161 Automatic trigger
Download

Workflow Description

An AI agent receives user questions via chat and translates them into SQL queries on PostgreSQL, maintaining conversation history while providing natural language responses. The system understands intent and retrieves relevant data seamlessly.

How it works

  1. 1.Receive the user message through supported chat channels
  2. 2.Process the query with OpenAI agent to understand intent and identify required data
  3. 3.Execute SQL queries on PostgreSQL and retrieve matching results
  4. 4.Maintain conversation history to ensure coherent multi-turn interactions
  5. 5.Send formatted answers back to the user in natural language

Use cases

  • Answer analytical questions about company data without writing SQL manually
  • Enable employees to interactively query database information in plain language
  • Build a smart assistant that understands natural language and converts questions into database queries

Requirements

  • OpenAI API key with sufficient quota and model access
  • PostgreSQL database with connection details and appropriate user permissions
  • Support for at least one chat platform (Telegram, Slack, or similar)

Service Value

Ideal as a smart automation service combining integrations and AI to produce ready-to-use results.

Apps Used

Chat Trigger AI Agent OpenAI Postgres Memory

Details

Trigger Automatic trigger
Nodes 11
Apps 5
Views 323
Downloads 161

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 (11)

/

When chat message received

Chat Trigger

#1

AI Agent

Agent

#2

OpenAI Chat Model

OpenAI

#3

Get Table Definition

Postgres Tool

#4

Sticky Note

Sticky Note

#5

Chat History

Memory Buffer Window

#6

Sticky Note3

Sticky Note

#7

Sticky Note1

Sticky Note

#8

Sticky Note2

Sticky Note

#9

Execute SQL Query

Postgres Tool

#10

Get DB Schema and Tables List

Postgres Tool

#11