Skip to content

Instantly share code, notes, and snippets.

@chandankumar4 chandankumar4/Postgres DB
Last active Dec 16, 2018

Embed
What would you like to do?
# Install PostSql (Ubuntu)
sudo apt-get install postgresql postgresql-contrib
------------------------------------------------------------------------------------------------------------------
# Delete PostSql (Ubuntu)
dpkg -l | grep postgres
sudo apt-get remove --purge postgresql postgresql-9.5 postgresql-client-9.5 postgresql-client-common postgresql-common postgresql-contrib postgresql-contrib-9.5
rm -r /etc/postgresql/
rm -r /etc/postgresql-common/
rm -r /var/lib/postgresql/
userdel -r postgres
groupdel postgres
------------------------------------------------------------------------------------------------------------------
# Postgress related command
sudo -u postgres psql # Login to database
ALTER USER postgres PASSWORD 'myPassword'; # change password
\list # list all postgres database name
\dt # list all table
\d gke # Display table properties
SELECT * FROM weather; # select data from table
CREATE TABLE account(id serial PRIMARY KEY,username VARCHAR (50) UNIQUE NOT NULL); # create table
INSERT INTO tablename (field1, field2) values ('value1', 2); # insert data in table
CREATE TABLE test(id INT PRIMARY KEY, sha VARCHAR, ref VARCHAR,status VARCHAR, web_url VARCHAR); # create table
UPDATE test SET STATUS = 'passed' WHERE id = 4956; # update row inside table
ALTER TABLE test3 ADD COLUMN jobs2 JSON[]; # Add column to table
SELECT id FROM test ORDER BY id DESC LIMIT 1 OFFSET 3; # Select 4th row id of table
------------------------------------------------------------------------------------------------------------------
# Useful links
https://www.calhoun.io/using-postgresql-with-go/
https://stackoverflow.com/questions/1109061/insert-on-duplicate-update-in-postgresql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.