# Which postgresql adapter to use for rails core? How about pr

**URL:** <https://www.ruby-forum.com/t/which-postgresql-adapter-to-use-for-rails-core-how-about-pr/76859>\
**Category:** Rails\
**Created:** [March 5, 2006, 10:29am UTC](https://www.ruby-forum.com/t/which-postgresql-adapter-to-use-for-rails-core-how-about-pr/76859 "2006-03-05T10:29:21Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![pergesu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@pergesu](https://www.ruby-forum.com/u/pergesu)\
**Post date:** [March 5, 2006, 10:29am UTC](https://www.ruby-forum.com/t/which-postgresql-adapter-to-use-for-rails-core-how-about-pr/76859/1 "2006-03-05T10:29:21Z")

</div>

I wanted to fix some things up in the trunk, so I set up the databases  
and ran the unit tests. A bunch fail for postgres, and even more  
error out. I know of two postgresql adapters: postgres-pr and  
ruby-postgres. Strangely, they each fail different tests. So if I  
want to fix things up, which one should I be using? For that matter,  
which adapter should I be using for production? Finding out that the  
Rails unit tests blow up for postgresql is not very reassuring.

Pat

---

<div class="post-metadata">

**Author:** ![pergesu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@pergesu](https://www.ruby-forum.com/u/pergesu)\
**Post date:** [March 5, 2006, 11:29am UTC](https://www.ruby-forum.com/t/which-postgresql-adapter-to-use-for-rails-core-how-about-pr/76859/2 "2006-03-05T11:29:34Z")

</div>

postgres-pr works very well for me - I’ve got a (private) Rails app  
that moves loads of data into and out of Postgres with it, and it’s  
never given me any problem whatsoever.

Regards

Dave M.

---

<div class="post-metadata">

**Author:** ![pergesu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@pergesu](https://www.ruby-forum.com/u/pergesu)\
**Post date:** [March 5, 2006, 7:50pm UTC](https://www.ruby-forum.com/t/which-postgresql-adapter-to-use-for-rails-core-how-about-pr/76859/3 "2006-03-05T19:50:33Z")

</div>

On Mar 5, 2006, at 2:33 AM, Lugovoi N. wrote:

> I use ruby-postgres (C binding) - works well for me 🙂
> 
> Latest available ruby-postgres-20051221 driver by default internally  
> converts query results and returns Ruby values, not strings.  
> This is convenient when using it outside Rails w/o ActiveRecord.

I just tried to update to the suggested version, and it broke tests.

It seems that version doesn’t play nicely with migrations.

Columns defined nullable (either implicitly or explicity) don’t get  
created as nullable.

I’m curious about your comment on return values. With the release  
version of the driver:

[http://ruby.scripting.ca/postgres/archive/ruby-postgres-0.7.1.tar.gz](http://ruby.scripting.ca/postgres/archive/ruby-postgres-0.7.1.tar.gz)

I get true/false for boolean, Date for date columns, and Time for  
timestamp with Rail 1.0. Perhaps it’s the Rails adapter doing the  
conversion as opposed to the driver?

In short, I’m a big believer in using the latest version, but from  
my perspective, the release version works perfectly with Rails 1.0,  
and the snapshot version does not.

–  
– Tom M.

---

<div class="post-metadata">

**Author:** ![pergesu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@pergesu](https://www.ruby-forum.com/u/pergesu)\
**Post date:** [March 6, 2006, 8:51am UTC](https://www.ruby-forum.com/t/which-postgresql-adapter-to-use-for-rails-core-how-about-pr/76859/4 "2006-03-06T08:51:09Z")

</div>

On 3/5/06, Tom M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> It seems that version doesn’t play nicely with migrations.
> 
> Columns defined nullable (either implicitly or explicity) don’t get  
> created as nullable.

I doubt it is driver problem, as migrations are Rails feature.  
What test failures you had except those I mentioned?

> I’m curious about your comment on return values. With the release  
> version of the driver:
> 
> [http://ruby.scripting.ca/postgres/archive/ruby-postgres-0.7.1.tar.gz](http://ruby.scripting.ca/postgres/archive/ruby-postgres-0.7.1.tar.gz)
> 
> I get true/false for boolean, Date for date columns, and Time for  
> timestamp with Rail 1.0. Perhaps it’s the Rails adapter doing the  
> conversion as opposed to the driver?

Yes, ActiveRecord performs conversion if the given value (from driver)  
is a String.

And here is example of difference in driver behaviour:

ruby-postgres-0.7.1:  
c = PGconn.new; c.query(“select true, false, 1, 2.4::float, ‘test’,  
now()::date, now()”)  
=\> [[“t”, “f”, “1”, “2.4”, “test”, “2006-03-06”, “2006-03-06  
09:39:56.859984+02”]]

ruby-postgres-20051221:  
c = PGconn.new; c.query(“select true, false, 1, 2.4::float, ‘test’,  
now()::date, now()”)  
=\> [[true, false, 1, 2.4, “test”, #\<Date: 4907601/2,0,2299161\>,  
#\<DateTime: 212008390801712003/86400000000,1/12,2299161\>]]

> In short, I’m a big believer in using the latest version, but from  
> my perspective, the release version works perfectly with Rails 1.0,  
> and the snapshot version does not.

As for me, snapshot version works better outside Rails 🙂

---

<div class="post-metadata">

**Author:** ![pergesu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@pergesu](https://www.ruby-forum.com/u/pergesu)\
**Post date:** [March 5, 2006, 11:35am UTC](https://www.ruby-forum.com/t/which-postgresql-adapter-to-use-for-rails-core-how-about-pr/76859/5 "2006-03-05T11:35:35Z")

</div>

I use ruby-postgres (C binding) - works well for me 🙂

Latest available ruby-postgres-20051221 driver by default internally  
converts query results and returns Ruby values, not strings.  
This is convenient when using it outside Rails w/o ActiveRecord.

As of rev3772 of rails and ruby-postgres-20051221 I had following 11  
test failures:

- 8 about type mismatch - expected Time, got DateTime from driver for  
TIMESTAMP columns.
- 2 about type mismatch - expected ‘t’, got from driver
- 1 related to this ticket: [http://dev.rubyonrails.org/ticket/3114](http://dev.rubyonrails.org/ticket/3114)
- Failure in test\_reset\_table\_with\_non\_integer\_pk(AdapterTest)  
[./test/adapter\_test.rb:56]

If I add to test/connections/native\_postgresql/connection.rb:

require ‘postgres’  
PGconn.translate\_results = false

then driver doesn’t parse query results and only one test fails  
[./test/adapter\_test.rb:56].

---

<div class="post-metadata">

**Author:** ![pergesu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@pergesu](https://www.ruby-forum.com/u/pergesu)\
**Post date:** [March 6, 2006, 2:45pm UTC](https://www.ruby-forum.com/t/which-postgresql-adapter-to-use-for-rails-core-how-about-pr/76859/6 "2006-03-06T14:45:36Z")

</div>

On Sun, 5 Mar 2006 21:26:55 +1100, David M. wrote:

> postgres-pr works very well for me - I’ve got a (private) Rails app  
> that moves loads of data into and out of Postgres with it, and it’s  
> never given me any problem whatsoever.

I’ve had trouble using postgres-pr on Windows with Webrick (development  
mode, of course) - left running long enough over my VPN, it eventually  
seems to lose its connection. Of course, I can’t say if that’s  
postgres-pr  
or just the protocol itself, since AFAIK Windows still can’t run the C  
bindings.

---

<div class="post-metadata">

**Author:** ![pergesu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@pergesu](https://www.ruby-forum.com/u/pergesu)\
**Post date:** [March 6, 2006, 6:12pm UTC](https://www.ruby-forum.com/t/which-postgresql-adapter-to-use-for-rails-core-how-about-pr/76859/7 "2006-03-06T18:12:50Z")

</div>

On Mar 5, 2006, at 11:48 PM, Lugovoi N. wrote:

> > It seems that version doesn’t play nicely with migrations.
> > 
> > Columns defined nullable (either implicitly or explicity) don’t get  
> > created as nullable.
> 
> I doubt it is driver problem, as migrations are Rails feature.  
> What test failures you had except those I mentioned?

Well, it’s some sort of problem between the driver and Rails. The  
same migrations work perfectly with ruby-postgres-0.7.1, but don’t  
work properly with ruby-postgres-20051221.

> Yes, ActiveRecord performs conversion if the given value (from driver)  
> ruby-postgres-20051221:  
> c = PGconn.new; c.query(“select true, false, 1, 2.4::float, ‘test’,  
> now()::date, now()”)  
> =\> [[true, false, 1, 2.4, “test”, #\<Date: 4907601/2,0,2299161\>,  
> #\<DateTime: 212008390801712003/86400000000,1/12,2299161\>]]
> 
> > In short, I’m a big believer in using the latest version, but from  
> > my perspective, the release version works perfectly with Rails 1.0,  
> > and the snapshot version does not.

Yes, outside of Rails having the driver do the conversions would be  
wonderful. Inside Rails they’re already done, and migrations work  
with the older version, so I’d recommend the older version under Rails.

–  
– Tom M.
