Postgresql - Kitasio/MyWebDev GitHub Wiki

First steps

  1. install: apt install postgres
  2. initialize pg_ctl -D /usr/local/var/postgres start
  3. create database createdb your_db
  4. connect psql -U username -d your_db

Inside the database

  1. create a new database create database your_database
  2. to connect \c your_database
  3. create table, example:
create table customer(
id serial primary key,
name varchar(255),
phome varchar(30),
email varchar(255)
);
  1. show relations \d, show the entity \d customer
  2. table example with a relation:
create table product_photo(
id serial primary key,
url varchar(255),
product_id integer references product(id)
);

Inside a table

  1. insert data into table insert into customer(name, phone, email) values ('Jon', '22', '[email protected]');
  2. to show everything in the table select * from customer