-
Notifications
You must be signed in to change notification settings - Fork 235
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
Order incompatible with Rails 5 (Postgres) #160
Comments
Hey @JonasNielsen, thanks for reporting. I'm not sure there's a great way to make this work with Rails 5, so I updated the docs. |
@ankane I'm facing the same issue. I'm using the irb(main):011:0> Punch.group_by_month(:average_time).count
(1.2ms) SELECT COUNT(*) AS count_all, (DATE_TRUNC('month', (average_time::timestamptz - INTERVAL '0 second') AT TIME ZONE 'Etc/UTC') + INTERVAL '0 second') AT TIME ZONE 'Etc/UTC' AS date_trunc_month_average_time_timestamptz_interval_0_second_at_ FROM "punches" WHERE (average_time IS NOT NULL) GROUP BY (DATE_TRUNC('month', (average_time::timestamptz - INTERVAL '0 second') AT TIME ZONE 'Etc/UTC') + INTERVAL '0 second') AT TIME ZONE 'Etc/UTC' ORDER BY punches.average_time DESC
ActiveRecord::StatementInvalid: PG::GroupingError: ERROR: column "punches.average_time" must appear in the GROUP BY clause or be used in an aggregate function
LINE 1: ...ERVAL '0 second') AT TIME ZONE 'Etc/UTC' ORDER BY punches.av...
^
: SELECT COUNT(*) AS count_all, (DATE_TRUNC('month', (average_time::timestamptz - INTERVAL '0 second') AT TIME ZONE 'Etc/UTC') + INTERVAL '0 second') AT TIME ZONE 'Etc/UTC' AS date_trunc_month_average_time_timestamptz_interval_0_second_at_ FROM "punches" WHERE (average_time IS NOT NULL) GROUP BY (DATE_TRUNC('month', (average_time::timestamptz - INTERVAL '0 second') AT TIME ZONE 'Etc/UTC') + INTERVAL '0 second') AT TIME ZONE 'Etc/UTC' ORDER BY punches.average_time DESC
from (irb):11 |
Thank you @ankane |
Adding .unscope(:order) as recommended fixed the issue for me pushing from Rails 4.2 to Rails 5.0.1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using
.order()
or.reverse_order
breaks with Postgres 9.3.1 and Rails 5.0.1.The text was updated successfully, but these errors were encountered: