1

Gem info - ruby 1.8.7, pg 0.9.0, postgres 0.8.1 All super old gems. I can't change that.

Code -

require 'rubygems'
require 'active_record'
require 'pg'
require 'postgres'

conn = PGconn.connect(:host => 'db.com', :port => 1234, :username => 'db1', :password => 'db1')
conn = PGconn.open
res = conn.exec("select * from a;")
PGconn.close

Require postgres line causes the following message and does not allow the code to execute. How do I make it work ? The warning is given below:

This is an old, deprecated version of the Ruby PostgreSQL driver that hasn't
been maintained or supported since early 2008.

You should install/require 'pg' instead.

If you need the 'postgres' gem for legacy code that can't be converted, you can
still install it using an explicit version, like so:

  gem install postgres -v '0.7.9.2008.01.28'
  gem uninstall postgres -v '>0.7.9.2008.01.28'

If you have any questions, the nice folks in the Google group can help:

  http://goo.gl/OjOPP / ruby-pg@googlegroups.com
stack1
  • 1,004
  • 2
  • 13
  • 28
  • Not much helpful info here - http://stackoverflow.com/questions/1664364/how-to-handle-ruby-on-rails-error-please-install-the-postgresql-adapter-gem or here http://stackoverflow.com/questions/15582618/capistrano-error-msg-please-install-the-pg-adapter-gem-install-activerecord-p Still stuck!!! – stack1 Apr 21 '15 at 21:19
  • Well, it says 'You should install/require 'pg' instead.'. Do you actually need the gem? I have Postgres running and only use the pg gem. – Johannes Jasper Apr 21 '15 at 21:35
  • @elactic - I have pg, postgres and active record. checked it using `gem list` command – stack1 Apr 21 '15 at 21:54
  • 1
    Is this in a script or something? Did you do what the warning message said to do? Uninstall the new `postgres` gem. You likely have a "current" (`0.8+`) version installed which has this warning. You may want to [use bundler](http://bundler.io) to get the right version of the gem you're needing instead of just relying on what's installed. – Nick Veys Apr 21 '15 at 22:02
  • @NickVeys - Yes, i did whatever the script told me to do. I have the pg gem, but its too old to work with all the online examples from google search. In old postgres, you used PGconn to make db conn. With new, you use PG class. PGconn won't work because the gem it comes from is deprecated. And all my gems come from bundler which points to our repo of dusty old gems. – stack1 Apr 22 '15 at 00:49
  • 1
    Are you using bundler in your script to ensure you get the right gem version? Having a Gemfile doesn't mean you are using bundler necessarily. You can specify one that isn't deprecated and use it. Otherwise you'll just get (I think) the most recent one upon require. – Nick Veys Apr 22 '15 at 01:17

0 Answers0