Skip to content

Instantly share code, notes, and snippets.

@injune1123
Last active June 10, 2019 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save injune1123/bf1215fd1a30aab1ff277500e3fb2ea4 to your computer and use it in GitHub Desktop.
Save injune1123/bf1215fd1a30aab1ff277500e3fb2ea4 to your computer and use it in GitHub Desktop.
Frequently used Postgresql commands
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