Last active
June 10, 2019 14:49
-
-
Save injune1123/bf1215fd1a30aab1ff277500e3fb2ea4 to your computer and use it in GitHub Desktop.
Frequently used Postgresql commands
This file contains hidden or 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
sudo su - postgres | |
create database #{DATABASE_NAME}; | |
psql -U postgres | |
//list all dbs | |
postgres-# \l | |
//connect to the db | |
postgres-# \c [database_name]: | |
//list all the tables in the current db | |
postgres-# \d: | |
//delete a row | |
DELETE FROM #{table_name} WHERE #{condition} | |
// common error when deleting a row | |
Error: update or delete on table #{table_name} violdates foreign key constraint #{a_key_name} on table #{table_name_2} | |
Detail: key is still referenced from the table #{table_name_2} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment