SQL is a Programming language used by most relational database management systems (RDBMS) to manage data stored in tabular form. SQL is a must-have skill for data scientists, analysts, and engineers.
An SQL table consists of labelled rows and columns. A relational database contains multiple tables that relate to each other by means of shared columns.
Sql provides numerous functions and methods to manage data stored in a relational database efficiently and accurately. There are many different relational database management systems (e.g. MySQL, PostgreSQL, SQL Server). The SQL syntax they adapt might differ slightly.
In this article, we will make a practical introduction to PostgreSQL, the world’s most advanced open source relational database.
PostgreSQL or commonly-used as Postgres, has been around for over 30 years. It is preferred by a lot of businesses across many different industries due to its robustness, reliability, and performance.
The official website provides instructions that clearly explain how to install PostgreSQL. Once installed, you can practice in psql which is an interactive terminal for working with PostgreSQL.
I use Postgres app for macOS. Once it is opened, you can select a database and click on start. It is common practice to have different databases for different projects.

I have selected the postgres database. Here is the initial screen of the psql terminal:

In order to see a list of all databases, we can use the "l" command.
postgres=# l

We can switch to another database in the psql terminal using the "c" command and the database name.
postgres=# c sonery
You are now connected to database "sonery" as user "sonery".
sonery=#
A relational database is likely to contain many tables. The "dt" command shows a list of the tables in the current database.
sonery=# dt
List of relations
Schema | Name | Type | Owner
-------+-------+-------+--------
public | sales | table | sonery
(1 row)
I have only one table called "sales" in my database. It seems like I contradict with I have just said about having many tables in a database. However, this is only for practicing.
Let’s create two new tables.
sonery=# CREATE TABLE inventory (
product_id int,
warehouse_id int,
stock_qty int,
date date
);
CREATE TABLE
sonery=# CREATE TABLE orders (
order_id int,
product_id int,
order_qty int,
date date
);
CREATE TABLE
The psql terminal returns "CREATE TABLE" to indicate that the table has been created successfully. Let’s check the tables in the current database again.
sonery=# dt
List of relations
Schema | Name | Type | Owner
-------+-----------+-------+--------
public | inventory | table | sonery
public | orders | table | sonery
public | sales | table | sonery
(3 rows)
We have created the inventory and orders tables but they are empty. The insert statement of SQL can be used to manually populate tables.
sonery=# INSERT INTO orders VALUES
(101, 1001, 2, '2021-01-04'), (102, 1423, 1, '2021-01-04'), (103, 1260, 5, '2021-01-13');
INSERT 0 3
We do not have to provide the name of the columns. However, we need to write the values appropriately regarding the column order.
If we provide the name of the columns, the values are inserted into the table according to the order we specify.
sonery=# INSERT INTO orders (order_id, date, product_id, order_qty)
VALUES (104, '2021-05-13', 1590, 5);
INSERT 0 1
The next example is about querying a table which is the most frequently used operation in a database. We write queries to retrieve data from a database. The select statement is used for writing queries.
sonery=# SELECT * FROM orders;
order_id | product_id | order_qty | date
---------+------------+-----------+------------
101 | 1001 | 2 | 2021-01-04
102 | 1423 | 1 | 2021-01-04
103 | 1260 | 5 | 2021-01-13
104 | 1590 | 5 | 2021-05-13
(4 rows)
The "*" means we want to retrieve all the columns. We can also write the desired column names.
sonery=# SELECT order_id, date FROM orders;
order_id | date
---------+------------
101 | 2021-01-04
102 | 2021-01-04
103 | 2021-01-13
104 | 2021-05-13
(4 rows)
Conclusion
We have done a basic introduction to PostgreSQL. Some of the examples are the general SQL examples so they will be helpful even if you are using a different RDBMS.
What we have covered in this article is only a small part of PostgreSQL and SQL in general. I plan to write more articles focusing on more advanced operations with PostgreSQL. Stay tuned!
Thank you for reading. Please let me know if you have any feedback.