Skip to main content

AI agent to chat with Supabase/PostgreSQL DB

Workflow preview

Workflow preview
100%
AI agent to chat with Supabase/PostgreSQL DB preview
Open on n8n.io

Important notice

This workflow is provided as-is. Please review and test before using in production.

1. Workflow Overview

Video Guide I prepared a detailed guide that showed the whole process of building a resume analyzer. [![OPENAI 14.png](https://res.cloudinary.com/de9jgixzm/image/upload/v1739773279/Youtube%20Thumbs...

Best for

  • Engineering automation workflows
  • AI Chatbot automation workflows
  • intermediate n8n builders looking for reusable templates

Tools used

n8n-nodes-base.stickynote, @n8n/n8n-nodes-langchain.chattrigger, @n8n/n8n-nodes-langchain.lmchatopenai, n8n-nodes-base.postgrestool, @n8n/n8n-nodes-langchain.agent

Source and attribution

This workflow is cataloged by N8N Workflows and links back to its original n8n.io source page by Mark Shcherbakov.

Original n8n.io source

1.1 Workflow description

Title
AI agent to chat with Supabase/PostgreSQL DB
Workflow name
AI agent to chat with Supabase/PostgreSQL DB

Video Guide

I prepared a detailed guide that showed the whole process of building a resume analyzer.

Who is this for?

This workflow is ideal for developers, data analysts, and business owners who want to enable conversational interactions with their database. It’s particularly useful for cases where users need to extract, analyze, or aggregate data without writing SQL queries manually.

What problem does this workflow solve?

Accessing and analyzing database data often requires SQL expertise or dedicated reports, which can be time-consuming. This workflow empowers users to interact with a database conversationally through an AI-powered agent. It dynamically generates SQL queries based on user requests, streamlining data retrieval and analysis.

What this workflow does

This workflow integrates OpenAI with a Supabase database, enabling users to interact with their data via an AI agent. The agent can:

  • Retrieve records from the database.
  • Extract and analyze JSON data stored in tables.
  • Provide summaries, aggregations, or specific data points based on user queries.
  1. Dynamic SQL Querying: The agent uses user prompts to create and execute SQL queries on the database.
  2. Understand JSON Structure: The workflow identifies JSON schema from sample records, enabling the agent to parse and analyze JSON fields effectively.
  3. Database Schema Exploration: It provides the agent with tools to retrieve table structures, column details, and relationships for precise query generation.

Setup

Preparation
  1. Create Accounts:
    • N8N: For workflow automation.
    • Supabase: For database hosting and management.
    • OpenAI: For building the conversational AI agent.
  2. Configure Database Connection:
    • Set up a PostgreSQL database in Supabase.
    • Use appropriate credentials (username, password, host, and database name) in your workflow.
N8N Workflow

AI agent with tools:

  1. Code Tool:
    • Execute SQL queries based on user input.
  2. Database Schema Tool:
    • Retrieve a list of all tables in the database.
    • Use a predefined SQL query to fetch table definitions, including column names, types, and references.
  3. Table Definition:
    • Retrieve a list of columns with types for one table.

1.2 Logical Blocks

This catalog entry is organized from the workflow JSON. The node-level section below shows the executable blocks available for review before importing the template.

2. Block-by-Block Analysis

Block 1 - Sticky Note3

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 2 - Sticky Note5

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 3 - Sticky Note6

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 4 - Sticky Note7

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 5 - When chat message received

Type / Role
@n8n/n8n-nodes-langchain.chatTrigger - chatTrigger
Config choices
Version 1.1

Block 6 - OpenAI Chat Model

Type / Role
@n8n/n8n-nodes-langchain.lmChatOpenAi - lmChatOpenAi
Config choices
Version 1

Block 7 - DB Schema

Type / Role
n8n-nodes-base.postgresTool - postgresTool
Config choices
Version 2.5

Block 8 - Get table definition

Type / Role
n8n-nodes-base.postgresTool - postgresTool
Config choices
Version 2.5

Block 9 - Sticky Note

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 10 - AI Agent

Type / Role
@n8n/n8n-nodes-langchain.agent - agent
Config choices
Version 1.6

Block 11 - Run SQL Query

Type / Role
n8n-nodes-base.postgresTool - postgresTool
Config choices
Version 2.5

3. Summary Table

Workflow AI agent to chat with Supabase/PostgreSQL DB
Complexity intermediate
Nodes 11
Categories Engineering, AI Chatbot
Author Mark Shcherbakov
Published 06 Dec 2024

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/2612/2612.json as the source template for this automation.

  2. 2. Import the template into n8n

    Open n8n, import the downloaded JSON, and review each node before activating the workflow.

  3. 3. Configure credentials and variables

    Replace placeholder credentials, API keys, webhook URLs, account IDs, and environment-specific values with your own settings.

  4. 4. Test with sample data

    Run the workflow manually or in a staging workspace, inspect node output, and confirm downstream systems receive the expected data.

  5. 5. Activate and monitor

    Enable the workflow only after testing, then monitor executions, errors, and rate limits during the first production runs.

5. General Notes & Resources

Review imported nodes carefully before activation. This catalog entry is intended to help you inspect the workflow structure, understand required services, and find related templates faster.

Node names, credentials, schedules, webhook paths, and external service limits may need adjustment for your workspace.

Frequently asked questions

What does AI agent to chat with Supabase/PostgreSQL DB do?

Video Guide I prepared a detailed guide that showed the whole process of building a resume analyzer. [![OPENAI 14.png](https://res.cloudinary.com/de9jgixzm/image/upload/v1739773279/Youtube%20Thumbs...

What do I need before importing this workflow?

Review the workflow JSON, configure any required credentials in n8n, and test the automation in a safe workspace before using it in production.

Can I customize this workflow?

Yes. Use the block-by-block analysis and the downloadable JSON to inspect each node, then adjust credentials, prompts, schedules, filters, or destinations for your Engineering, AI Chatbot use case.