Chat with Supabase PostgreSQL using AI

Sheldon Niu
4 min readFeb 3, 2024

--

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’:

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

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

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.

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.

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:

And then AYD will begin creating tables for you:

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

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:

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

Getting data insights

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

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:

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!

Originally published at https://www.askyourdatabase.com on February 3, 2024.

--

--