putline undefined for PGconn

If you’re running a recent version of Rails, the PostgreSQL ActiveRecord adapter has been updated, requiring an updated Pg driver. If you were previously using putline for doing a PostgreSQL COPY inside of Ruby, you’ll need to change two method calls accordingly if you’re getting an exception:

undefined method `putline' for #<PGconn:0xb63968e8>

In a migration, I now have:

c = PostalCode.connection.raw_connection
c.exec(%q{
	COPY postal_codes (
		iso_code, postal_code, locality, region, region_code,
		county, county_code, community, latitude, longitude, accuracy
	) FROM STDIN
})
data = File.open(File.dirname(__FILE__) + '/postal_codes.pgdump') {|f| f.read }
data.each_line {|line| c.put_copy_data(line) }
c.put_copy_end

Oh, and my postal code dataset comes from geonames.

One Comment

  1. Posted 3/8/2011 at 5:07 pm | Permalink

    Thanks for the post, I am glad I found it as you helped me get around having to mess with my linux server permissions for the postgres user in order to use COPY…. these changes to the PG sql AR adapter dont seem to be written about, at least on earlier searches no luck.

Post a Comment

Your email is never shared. Required fields are marked *

*
*