PostgreSQL Quickstart
PostgreSQL command line operations for my future reference.
Launch PostgreSQL through SQL Shell
Enter your previously set password, you should see
Inside the database called postgres, list all the databases available in this server, type:
postgres=# \l
Create a new database
postgres=# CREATE DATABASE new_database;
Close the postgres database. Relaunch the server through SQL Shell. This time use the newly created database new_database directly.
List all the tables inside the database.
new_database=# \d
Create a new table
CREATE TABLE person (
id BIGSERIAL NOT NULL PRIMARY KEY,
name VARCHAR(100) NOT NULL,
country VARCHAR(50) NOT NULL);
INSERT INTO person (name, country) VALUES ('Amigoscode', 'UK');
INSERT INTO person (name, country) VALUES ('Sarah', 'Albania');
INSERT INTO person (name, country) VALUES ('Julio', 'Argentina');
UPDATE person SET name = 'Antonio' WHERE id = 3;
DELETE FROM person WHERE id = 2;
Toggle expanded display:
new_database=# \x
To execute query from a file:
new_database=# \i <the-path-to-sql-file>