Chat with Supabase PostgreSQL using AI
![Sheldon Niu](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2Fide6mbkk%2Fproduction%2F77d3f5e2569ddf41f731e970abd75c701d76feca-800x800.jpg%3Fw%3D96%26h%3D96%26fit%3Dcrop%26auto%3Dformat&w=256&q=75)
![Chat with Supabase PostgreSQL using AI](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2Fide6mbkk%2Fproduction%2F20e22efcf0630deb1c262eddbcc94450aee0313a-1200x675.jpg%3Frect%3D0%2C38%2C1200%2C600%26w%3D2000%26h%3D1000%26fit%3Dmax%26auto%3Dformat&w=3840&q=75)
![Sheldon Niu](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2Fide6mbkk%2Fproduction%2F77d3f5e2569ddf41f731e970abd75c701d76feca-800x800.jpg%3Fw%3D96%26h%3D96%26fit%3Dcrop%26auto%3Dformat&w=256&q=75)
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](https://cdn.sanity.io/images/ide6mbkk/production/e43eec765e4215bdb2576436ea371953c3885fc6-3430x1690.png?w=3840&q=75&fit=clip&auto=format)
Give your project a name, select a region (where your PostgreSQL will be hosted), and then click "Create".
![Create project in Supabase](https://cdn.sanity.io/images/ide6mbkk/production/e245fb46c7357c0d91941f7b4ab3981ecfad5eb1-2462x1754.png?w=3840&q=75&fit=clip&auto=format)
Then navigate to "Project Settings" -> "Database". You will see your connection string under "Database Settings".
![Connection string in supabase](https://cdn.sanity.io/images/ide6mbkk/production/93923cfbc7c92408cd65efa6d94d3a78d674ef77-3416x1750.png?w=3840&q=75&fit=clip&auto=format)
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](https://cdn.sanity.io/images/ide6mbkk/production/b9e62622cafc9e8be88dbfbc484cc0384d3439eb-2262x1276.png?w=3840&q=75&fit=clip&auto=format)
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](https://cdn.sanity.io/images/ide6mbkk/production/faf5fc0670aae845f769ab89d47b3999b9d3df4b-2262x1276.png?w=3840&q=75&fit=clip&auto=format)
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](https://cdn.sanity.io/images/ide6mbkk/production/7a936366ddd23d85b4fdab841e53da08aaae1e51-1394x604.png?w=3840&q=75&fit=clip&auto=format)
And then AYD will begin creating tables for you:
![Successfully created tables without writing SQL using AI](https://cdn.sanity.io/images/ide6mbkk/production/ead46ea68982f9b4ee052278d39e2597ad2229ab-1614x1504.png?w=3840&q=75&fit=clip&auto=format)
Now we should have three tables. Let's go to the Supabase Schema Viewer to view them:
![View schema in Supabase Schema Visualizer](https://cdn.sanity.io/images/ide6mbkk/production/734d21a28bb2d90a014c4c2677d9a024c8fd01fb-3454x1678.png?w=3840&q=75&fit=clip&auto=format)
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](https://cdn.sanity.io/images/ide6mbkk/production/5efe25212d56b08a4b93c568cd4d24bed95b59e1-1608x1384.png?w=3840&q=75&fit=clip&auto=format)
Go to the Supabase Table Editor to view the inserted data:
![View data in Supabase table editor](https://cdn.sanity.io/images/ide6mbkk/production/c851f4c0b041e6b18aea1513d3d11c827cde8ac2-3450x1716.png?w=3840&q=75&fit=clip&auto=format)
Getting data insights
Let's ask which customer has contributed the highest sales amount:
![get insights](https://cdn.sanity.io/images/ide6mbkk/production/a7de4a0afce641239d3615a328c392430d38182c-1604x536.png?w=3840&q=75&fit=clip&auto=format)
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](https://cdn.sanity.io/images/ide6mbkk/production/6b306e0df151403f7b3313522da40a041b75639e-1616x1560.png?w=3840&q=75&fit=clip&auto=format)
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!