Postgresql - Kitasio/MyWebDev GitHub Wiki
First steps
- install:
apt install postgres
- initialize
pg_ctl -D /usr/local/var/postgres start
- create database
createdb your_db
- connect
psql -U username -d your_db
Inside the database
- create a new database
create database your_database
- to connect
\c your_database
- create table, example:
create table customer(
id serial primary key,
name varchar(255),
phome varchar(30),
email varchar(255)
);
- show relations
\d
, show the entity \d customer
- 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
- insert data into table
insert into customer(name, phone, email) values ('Jon', '22', '[email protected]');
- to show everything in the table
select * from customer