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

PG error with v3.2.0 #519

Closed
aoredo opened this issue May 2, 2014 · 9 comments · Fixed by #570
Closed

PG error with v3.2.0 #519

aoredo opened this issue May 2, 2014 · 9 comments · Fixed by #570
Labels

Comments

@aoredo
Copy link

aoredo commented May 2, 2014

Hello,

I am getting this error while generating a tag_cloud from a tagged_with instance when upgraded to 3.2.0.

@images = Media.tagged_with(params[:search].strip.gsub(' ', '').gsub('-', '')).order(mylike: :desc).page params[:page]

@tags = @images.tag_counts_on(:tags).limit(20)

@tags is then used to generate the tag_cloud but I am getting the error below. When i revert back to 2.4.1, it worked perfectly. Any suggestions?

_Error_*
ActionView::Template::Error (PG::InvalidColumnReference: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list
LINE 1: ...' AND media_taggings_b910fb9.tag_id = 1 ORDER BY "media"."m...
^
: SELECT COUNT(*) FROM "tags" JOIN (SELECT taggings.tag_id, COUNT(taggings.tag_id) AS tags_count FROM "taggings" INNER JOIN media ON media.id = taggings.taggable_id WHERE (taggings.taggable_type = 'Media' AND taggings.context = 'tags') AND (taggings.taggable_id IN(SELECT DISTINCT media.id FROM "media" JOIN taggings media_taggings_b910fb9 ON media_taggings_b910fb9.taggable_id = "media".id AND media_taggings_b910fb9.taggable_type = 'Media' AND media_taggings_b910fb9.tag_id = 1 ORDER BY "media"."mylike" DESC LIMIT 24 OFFSET 0)) GROUP BY taggings.tag_id HAVING COUNT(taggings.tag_id) > 0) AS taggings ON taggings.tag_id = tags.id):

@seuros
Copy link
Collaborator

seuros commented May 2, 2014

Can you write a script to reproduce this error ?

@seuros seuros added the bug label May 2, 2014
@seuros seuros modified the milestone: 3.2.0 May 2, 2014
@aoredo
Copy link
Author

aoredo commented May 2, 2014

Sorry I am newbie, what do you mean by a script?

@seuros
Copy link
Collaborator

seuros commented May 2, 2014

A rails application with only the models that causing the error (you can strip out all logic from it)

try to remove : .order(mylike: :desc)

@bf4
Copy link
Collaborator

bf4 commented May 2, 2014

@aoredo Any example code. The model, the schema for the model, the relevant code in the model, the db type and version, the rails version, command you're running when you get the error, the backtrace

@vanboom
Copy link

vanboom commented May 19, 2014

This reproduces it...
User.tagged_with(params[:tag]).order("lower(lname) asc") produces
SELECT DISTINCT USERS.* FROM USERS JOIN TAGGINGS USERS_TAGGINGS_53FE430.TAGGABLE_TYPE = 'USER' ....

User.order("lower(lname) asc") produces
SELECT USERS.* FROM USERS WHERE USERS.ACTIVE='T' ORDER BY LOWER(LNAME) ASC

I believe the addition of the DISTINCT argument is causing the issue.

@seuros
Copy link
Collaborator

seuros commented May 19, 2014

Ok, i will try to resolve this, once i have free time.

@seuros seuros closed this as completed May 19, 2014
@seuros seuros reopened this May 19, 2014
@dkonayuki
Copy link

I have this problem too. Probably because of DISTINCT when I try to ORDER by some fields not in SELECT DISTINCT operation.

@seuros
Copy link
Collaborator

seuros commented Jun 25, 2014

@dkonayuki Can you provide a dummy application with the issue ??

@smathieu
Copy link

FYI, I'm running on the same issue. Any model that uses tagged_with(params[:tags], any: true) and a order(...) clause seems to break this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants