Last Updated: February 25, 2016
·
311
· levity

A tiny little script for psql and database URL's

I got tired of taking database URL's in the format postgres://user:password@host:port/database and manually pulling out the arguments in order to use psql, so I wrote this:

#!/usr/bin/env ruby
require 'uri'
u = URI.parse ARGV.first
exec "PGPASSWORD=#{u.password} psql -U #{u.user} -h #{u.host} -p #{u.port} #{u.path.sub('/', '')}"

I saved it in /usr/local/bin/psqlu, so I can call it like this:

psqlu postgres://user:password@host:port/database