Skip to content

Instantly share code, notes, and snippets.

@stephenquan
Created April 30, 2018 05:08
Show Gist options
  • Save stephenquan/f6fc9406765615b30fc15f8f18754710 to your computer and use it in GitHub Desktop.
Save stephenquan/f6fc9406765615b30fc15f8f18754710 to your computer and use it in GitHub Desktop.
psql_demo.sh
# Demonstrates psql command line client on Ubuntu machines
# See: https://www.postgresql.org/download/linux/ubuntu/
cat $HOME/.pgpass <<EOF
$PGHOST:5432:$PGINST:$PGUSER:$PGPASS
EOF
psql -h $PGHOST -p 5432 -U $PGUSER $PGINST -t -f - <<EOF
drop table primes;
create table primes (
num int not null primary key,
txt text
);
insert into primes values (2, 'two');
insert into primes values (3, 'three');
insert into primes values (5, 'five');
insert into primes values (5, 'lima') on conflict (num) do update set txt = 'lima';
select * from primes;
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment