Ruby Postgres script
Swami Nikhilaananda said:
"Ruby is a gem of a language"
There was a very simple requirement that I had - I wanted to write a script to update a postgres table. On looking up quite a few resources also, I was unable to solve the issue that I was facing. Let me put down the completely stripped down version of the script here first...
"Ruby is a gem of a language"
There was a very simple requirement that I had - I wanted to write a script to update a postgres table. On looking up quite a few resources also, I was unable to solve the issue that I was facing. Let me put down the completely stripped down version of the script here first...
#!/usr/bin/rubyThis script is the typical script that you will find on looking up any site. However, the error that you will face on running this is the following:
require 'postgres'
conn = PGconn.connect("localhost", 5432, '', '', "tblName", "username", "password")
puts conn
... `require': no such file to load -- postgres (LoadError) ...This was quite annoying... Finally I discovered the required solution. So, I thought that this needs to be shared. Though it appears to be trivial, it is definitely not something that I could find with ease :)
#!/usr/bin/rubyThat line needs to come before you add require for others. Then it works like a charm <-- well, everyone uses that line :P So, thought I should too :-)
require 'rubygems'
require 'postgres'
conn = PGconn.connect("localhost", 5432, '', '', "tblName", "username", "password")
puts conn
Comments