Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

returned type inconsistency: COUNT(a) returns a string #91

Closed
ged opened this issue Nov 15, 2011 · 1 comment
Closed

returned type inconsistency: COUNT(a) returns a string #91

ged opened this issue Nov 15, 2011 · 1 comment

Comments

@ged
Copy link
Owner

ged commented Nov 15, 2011

Original report by Anonymous.


I've had this code, that worked as expected on localhost with sqlite3 but not on Heroku.

This query creates a recordset of how many records were created per day:

#!ruby

votes = Game.find(13).user_votes.select("user_votes.created_at, COUNT(user_votes.id) as count").order("user_votes.created_at ASC").group("user_votes.created_at")

Now if you check

#!ruby

votes[0].count.is_a?(Integer)
votes[0].count.as_a?(String)

with sqlite3 you will get true, false. But with PG, it'll be false, true.

@ged
Copy link
Owner Author

ged commented Nov 15, 2011

Original comment by Michael Granger (Bitbucket: ged, GitHub: ged).


You're using some other library on top of 'pg', and it's that library's responsibility to do any conversion between PostgreSQL's columns and its equivalent Ruby datatype. The 'pg' library explicitly and intentionally doesn't do any datatype conversion of any column value in its result set, as different higher-level libraries have different ideas about what Ruby class and conversion mechanism is appropriate.

For more details on the design philosophy for low-level PostgreSQL client libraries, see the [[http://wiki.postgresql.org/wiki/Driver_development|Driver Development article]] in the PostgreSQL wiki.

@ged ged closed this as completed Nov 15, 2011
@ged ged added this to the Pending milestone Oct 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant