Skip to main content

Command Palette

Search for a command to run...

Creating Tables in Postgres

Published
2 min read
M

As a former 3D Animator with more than 12 years of experience, I have always been fascinated by the intersection of technology and creativity. That's why I recently shifted my career towards MERN stack development and software engineering, where I have been serving since 2021.

With my background in 3D animation, I bring a unique perspective to software development, combining creativity and technical expertise to build innovative and visually engaging applications. I have a passion for learning and staying up-to-date with the latest technologies and best practices, and I enjoy collaborating with cross-functional teams to solve complex problems and create seamless user experiences.

In my current role as a MERN stack developer, I have been responsible for developing and implementing web applications using MongoDB, Express, React, and Node.js. I have also gained experience in Agile development methodologies, version control with Git, and cloud-based deployment using platforms like Heroku and AWS.

I am committed to delivering high-quality work that meets the needs of both clients and end-users, and I am always seeking new challenges and opportunities to grow both personally and professionally.

Now that we have a basic database design, the next step is to write SQL to create our first table.

In this lesson, we will create a table called cities with four columns:

  • name

  • country

  • population

  • area

We will run all SQL inside Supabase using its built-in SQL Editor.


Where Do We Write SQL in Supabase?

In Supabase:

  1. Open your Supabase project

  2. Go to SQL Editor

  3. Click New Query

  4. Write your SQL and press Run

Behind the scenes, this is what is happening:

  • Supabase (the dashboard) acts like a client

  • You write SQL in the SQL Editor

  • Supabase sends that SQL to the PostgreSQL database

  • PostgreSQL runs it and sends back the result

So yes — you are working with a real PostgreSQL database.


The SQL to Create the cities Table

Now let’s write the SQL.

create table cities (
  name varchar(50),
  country varchar(50),
  population integer,
  area integer
);

What this SQL means

  • create table cities → create a table named cities

  • Inside ( ... ) we define columns

  • Each column has:

    • a column name

    • a data type


Column Data Types (Simple Explanation)

varchar(50)

  • Used for text (strings)

  • (50) means: max length 50 characters
    Example: Tokyo, Pakistan, Karachi

So:

  • name varchar(50) → city name as text

  • country varchar(50) → country name as text

integer

  • Used for whole numbers
    Example: 100, 50000, 20000000

So:

  • population integer → population as a number

  • area integer → area as a number


Common Things to Double Check

Before you run the query:

  • ✅ commas after each line except the last one

  • ✅ parentheses are correct

  • ✅ semicolon ; at the end


After Running the Query

When you click Run:

  • PostgreSQL creates the cities table in your database

  • You can see it in Supabase as well:

Go to:
Table Editor → public → cities

You should see the table with these columns:

  • name

  • country

  • population

  • area

At this point, your table is ready — and in the next step, we can start inserting data into it.


Quick Note

This query created a table successfully, but we will improve it later (for example, adding an id column).

For now, this is perfect for understanding the basics of table creation.