Last active
March 27, 2024 17:00
-
-
Save juliarose/7d9e841fc735b9c18c13a1878189d169 to your computer and use it in GitHub Desktop.
Postgres 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
# Connect remotely from command line | |
psql -h <REMOTE HOST> -p 5432 -U <DB_USER> <DB_NAME> | |
# USE database; | |
\c databasename; | |
# SHOW TABLES; | |
\dt; | |
# SHOW COLUMNS FROM tablename | |
\d+ tablename; | |
# CREATE TABLE | |
CREATE TABLE persons ( | |
id SERIAL NOT NULL PRIMARY KEY, | |
name VARCHAR(100) NOT NULL, | |
social_security_number VARCHAR(100) NOT NULL UNIQUE, | |
credit_score INT, | |
married BOOLEAN NOT NULL, | |
birth_date DATE NOT NULL, | |
details JSON NOT NULL | |
); | |
# INSERT INTO | |
INSERT INTO persons ( | |
id, | |
name | |
) | |
VALUES ( | |
1, | |
'Julia' | |
) | |
RETURNING name; | |
# SELECT | |
SELECT id, name FROM persons | |
WHERE | |
name = 'Julia'; | |
# UPDATE | |
UPDATE persons | |
SET | |
name = 'Julianna' | |
WHERE | |
name = 'Julia'; | |
# DELETE | |
DELETE FROM persons | |
WHERE | |
name = 'Julianna'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment