PostgresError #23

Closed
jpgarcia opened this Issue Dec 6, 2009 · 8 comments

Projects

None yet

2 participants

@jpgarcia
jpgarcia commented Dec 6, 2009

I'm getting this when running on Heroku because of Postgres database:

PostgresError - ERROR: column "medium.sector" must appear in the GROUP BY clause or be used in an aggregate function

Query: SELECT COUNT(*) FROM "medium" ORDER BY "sector" DESC:

BTW: running it locally with sqlite3 is working like a charm, thanks for the gem!

@jpgarcia
jpgarcia commented Dec 6, 2009

I fixed it by adding a line ( query.delete :order ) in the page method, agree with that?:

def page page = nil, options = {}
  options, page = page, nil if page.is_a? Hash
  page ||= pager_option :page, options
  options.delete :page
  page = 1 unless (page = page.to_i) && page > 1
  per_page = pager_option(:per_page, options).to_i
  query = options.dup
  collection = new_collection scoped_query(options = {
    :limit => per_page,
    :offset => (page - 1) * per_page,
    :order => [:id.desc]
  }.merge(query))
  query.delete :order <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  options.merge! :total => count(query), :page => page
  collection.pager = DataMapper::Pager.new options
  collection
end
@tj
Owner
tj commented Dec 6, 2009

That is something to take up with DM core, I would not go explicitly deleting :order, because it works fine with other RDMS

@jpgarcia
jpgarcia commented Dec 6, 2009

Ok, anyway removing the option :order will not affect the collection itself, I'm removing the :order only for the aggregate function "count", because the order hasn't any sense for an aggregate function.
thanks for your quickly answer!

@tj
Owner
tj commented Dec 6, 2009

ah, right sorry didnt look closely enough lol its probably fine then

@tj
Owner
tj commented Dec 7, 2009

Cool cool I committed the change :D thanks. Your totally right though I just had read it wrong originally when I scanned over the issue

@jpgarcia
jpgarcia commented Dec 7, 2009

good man! now I'm going to remove the monkey patch :)

@jpgarcia

hi visionmedia, it's been a long time since my last message and untill now I didn't deployed the app to heroku and now I'm realizing that the gem still throwing the same exception, this is because you removed the :order option to the 'options' instead of to the 'query' as I wrote in my second message.
hope you can modify it for the next version.

@tj
Owner
tj commented Dec 19, 2009

My bad! typo, 1.0.1 fixes this

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment