Last active
September 29, 2020 08:30
-
-
Save megpay/d08ae2c80cf21c5369eeacdac5e11c0e to your computer and use it in GitHub Desktop.
Useful postgresql commands
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Basic viewing the structure commands */ | |
\c database_name --connect to a database. | |
\dt --view the tables. this filters out non-table relations. | |
\d --view the tables. Includes non-table relations. | |
\d tablename --view the columns of the table. | |
/* Create a table and import from a csv into that table. */ | |
CREATE TABLE employees ( | |
id SERIAL, | |
first_name varchar(100), | |
last_name varchar(100), | |
dob date, | |
email varchar(255), | |
PRIMARY KEY (id) | |
); | |
\COPY employees(first_name, last_name, dob, email) | |
FROM '~/employees.csv' | |
DELIMITER ',' | |
CSV HEADER; | |
/* Dumping a psql database to a tar file */ | |
pg_dump -U postgres_username -h localhost -W -F t databasename > postgres_dump.tar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment