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

Syntax error calling count on multisearch results #127

Closed
jsierles opened this issue Jul 14, 2013 · 2 comments
Closed

Syntax error calling count on multisearch results #127

jsierles opened this issue Jul 14, 2013 · 2 comments

Comments

@jsierles
Copy link

With a Rails 4 app, I've added a single column to multisearch, and get a syntax error from Postgres 9.1 when calling count on the results:

irb(main):017:0> PgSearch.multisearch("olvidar").count
   (0.7ms)  SELECT COUNT("pg_search_documents".*, ((ts_rank((to_tsvector('simple', coalesce("pg_search_documents"."content"::text, ''))), (to_tsquery('simple', ''' ' || 'olvidar' || ' ''')), 0))) AS pg_search_rank) FROM "pg_search_documents"  WHERE (((to_tsvector('simple', coalesce("pg_search_documents"."content"::text, ''))) @@ (to_tsquery('simple', ''' ' || 'olvidar' || ' '''))))
PG::Error: ERROR:  syntax error at or near "AS"
LINE 1: ...ery('simple', ''' ' || 'olvidar' || ' ''')), 0))) AS pg_sear...
                                                             ^
: SELECT COUNT("pg_search_documents".*, ((ts_rank((to_tsvector('simple', coalesce("pg_search_documents"."content"::text, ''))), (to_tsquery('simple', ''' ' || 'olvidar' || ' ''')), 0))) AS pg_search_rank) FROM "pg_search_documents"  WHERE (((to_tsvector('simple', coalesce("pg_search_documents"."content"::text, ''))) @@ (to_tsquery('simple', ''' ' || 'olvidar' || ' '''))))
ActiveRecord::StatementInvalid: PG::Error: ERROR:  syntax error at or near "AS"
@daisybill-dev
Copy link

Are you using rails 4-0-stable? I ran into this same issue while using stable, but not with 4.0.0. I believe the reason is in here: rails/rails#10710

You should be able to fix the problem by using count(:all) rather than just count.

@jsierles
Copy link
Author

Yep, that was the reason.

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

No branches or pull requests

2 participants