background

Chat with Supabase PostgreSQL using AI

Chat with Supabase PostgreSQL using AI
Sheldon Niu
Sheldon Niu

Supabase is the state-of-the-art, open-source alternative to Google's Firebase, and its built-in PostgreSQL has a lot of functionalities, such as vector search and authentication, making it a popular choice for PostgreSQL hosting platforms.

If you are using Supabase as your PostgreSQL provider, then AskYourDatabase is a great choice for you to design your schema, query data, and visualize your data without writing SQL.

In this tutorial, we are going to set up a PostgreSQL database running on Supabase and connect it to AskYourDatabase to design schemas & query data in natural language.

Setting up Supabase database

First, head to your Supabase dashboard and click 'New Project':

Supabase dashboard
Supabase dashboard

Give your project a name, select a region (where your PostgreSQL will be hosted), and then click "Create".

Create project in Supabase
Create project in Supabase

Then navigate to "Project Settings" -> "Database". You will see your connection string under "Database Settings".

Connection string in supabase
Connection string in supabase

Downloading AskYourDatabase

Visit here to download the AskYourDatabase Desktop app, and click "Open". You will be directed to the page where you can connect your database.

Download AskYourDatabase
Download AskYourDatabase

Paste the connection string you just copied, replacing the password placeholder with your actual password, and click "Connect".

If the connection is successful, you will be navigated to the chat interface.

Chat with PostgreSQL using AI
Chat with PostgreSQL using AI

Designing schema & inserting data

Creating tables

Since our database is empty at the moment, we need to create some tables and insert some mock data.

We can let AskYourDatabase handle this. First, ask AYD to create "customer", "sales", and "product" tables with appropriate fields:

Create pg tables using plain english
Create pg tables using plain english

And then AYD will begin creating tables for you:

Successfully created tables without writing SQL using AI
Successfully created tables without writing SQL using AI

Now we should have three tables. Let's go to the Supabase Schema Viewer to view them:

View schema in Supabase Schema Visualizer
View schema in Supabase Schema Visualizer

Now you can see that the fields and table relations have all been created properly with a single question! This level of simplicity and efficiency is only possible with AskYourDatabase.

Inserting mockup data

Let's insert some realistic mockup data into these tables by asking questions in AskYourDatabase:

Insert mockup data into PostgreSQL using AI
Insert mockup data into PostgreSQL using AI

Go to the Supabase Table Editor to view the inserted data:

View data in Supabase table editor
View data in Supabase table editor

Getting data insights

Let's ask which customer has contributed the highest sales amount:

get insights
get insights

With a single question, it informs us that John Doe has contributed the most by executing the correct SQL query.

Data Visualization

Let's draw a pie chart to show the contribution to sales amounts by different customers:

data visualization
data visualization

Conclusion

Supabase stands out as one of the most popular PostgreSQL hosting providers, and with AskYourDatabase, designing schemas, and obtaining insights interactively through a chat interface becomes a breeze, all without the need to write SQL.

This is incredibly beneficial for those who aren't proficient in SQL or prefer not to engage with it directly. It also empowers teams without technical backgrounds to gain insights without needing engineering assistance.

Supabase and AskYourDatabase together make a winning combination!


More Blogs

Query SQL database in natural language

Query SQL database in natural language

The best approach depends on your team and whether you can invest time in building a SQL AI Agent. For technical teams who want more customized solutions, tools like Langchain may be the best choice. For non-tech teams, choosing tools like AskYourDatabase will likely be the lowest-cost option.

Sheldon Niu
Sheldon Niu
How AskYourDatabase has saved 40 hours per week for SmartLead.ai

How AskYourDatabase has saved 40 hours per week for SmartLead.ai

AskYourDatabase has helped the famous cold email SaaS company SmartLead.ai save 40 hours each week between the CS team and the engineering team. More importantly, the tool has taught the CS team the skills crucial for their growth and success.

Sheldon Niu
Sheldon Niu
;