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

Added PostgreSQL support for plusminus_tally #36

Closed
wants to merge 2 commits into from

Conversation

kevinelliott
Copy link

Database agnostic type_for_sql injection for typecast in select's SUM.
Use the provided column_names_for_tally for enumerating the current table's column names since PostgreSQL requires it when you use aggregate functions (this could alternately be used in the select instead of the group).

…o_sql to figure out the current database's equivalent to INTEGER.
…ns need to be specified when using aggregate functions or the glob select will not work.
@bouchard
Copy link
Owner

Sorry, MySQL doesn't like that, still not sure how to do this properly between Postgres / MySQL. Error is:


ActiveRecord::StatementInvalid: Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'int(11)) WHEN 1 THEN 1 WHEN 0 THEN -1 ELSE 0 END) AS plusminus, COUNT(votes.id) ' at line 1: SELECT items.*, SUM(CASE CAST(votes.vote AS int(11)) WHEN 1 THEN 1 WHEN 0 THEN -1 ELSE 0 END) AS plusminus, COUNT(votes.id) AS vote_count FROM `items` LEFT OUTER JOIN votes ON items.id = votes.voteable_id GROUP BY items.id, items.user_id, items.name, items.description ORDER BY plusminus DESC

@bouchard bouchard closed this Feb 23, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants