DEV Community

Cover image for Intro to PostgreSQL
Hunt Navar
Hunt Navar

Posted on

Intro to PostgreSQL

PostgreSQL is open-sourced object-relational database management system that is extremely dynamic and has many different use cases. Postgres, being a object-relational database, stores relationships as tuples.
Image description

The object-relational part of Postgres means that Postgres includes features like table inheritance and function overloading.

Think of table inheritance like making a class and then extending all the methods and information from one class to its child classes. Function overloading is creating multiple functions with the same name as long as the arguments are different.

Postgres also supports multiple different languages and can have different languages for different parts of the database. This aspect is great because it widens the amount of people who are able to use the manager as well as will allow people to use the languages best suited for the job at hand.

The DDL or data definition language of Postgres strongly resembles that of SQL. The common data definitions are Create, Drop, Alter, or Truncate.
Image description

CREATE DATABASE Bookshelf;

CREATE TABLE Borrowers (
id INT PRIMARY KEY,
first_name VARCHAR(20) not null,
last_name VARCHAR(50) not null,
birth_date DATE not null);

ALTER TABLE Borrowers ADD COLUMN years_member INT NOT NULL CHECK years_member > 0;

CREATE TABLE books (
id INT PRIMARY KEY,
title VARCHAR(50),
author VARCHAR(50)
publication_date DATE not null);

/* after populating ‘books‘ table */

TRUNCATE TABLE books;

/* removes all data from ‘books’ table */

The DML or data manipulation language is used to work with our tables. The common DML includes Insert, Update, Delete, or Select.

Image description

Since Postgres is open-source new features and updates common and documentation is excellent.

Overall Postgres is a powerful, excellent database manager that enhances traditional SQL.

Source: https://developer.okta.com/blog/2019/07/19/mysql-vs-postgres
Source: https://dev.to/hoverbaum/how-to-add-code-highlighting-to-your-devto-posts-2lp6
Source: https://www.postgresqltutorial.com/

Top comments (0)