Skip to content

ActiveRecord::StatementInvalid (PG::SyntaxError: ERROR: syntax error at or near "AS" #199

@homanchou

Description

@homanchou

Upgraded from pg_search 0.7 and rails 4.0.5 to pg_search 0.7.8 and rails 4.2.beta4

Now getting this error:

ActiveRecord::StatementInvalid (PG::SyntaxError: ERROR: syntax error at or near "AS"

The old query from 0.7 looked like:

SELECT COUNT(*) FROM "merchants" WHERE (((setweight(to_tsvector('simple', coalesce("merchants"."email"::text, '')), 'A') || setweight(to_tsvector('simple', coalesce("merchants"."company_name"::text, '')), 'B') || setweight(to_tsvector('simple', coalesce("merchants"."first_name"::text, '')), 'C') || setweight(to_tsvector('simple', coalesce("merchants"."last_name"::text, '')), 'D')) @@ (to_tsquery('simple', ''' ' || '[email protected]' || ' ''' || ':*'))) OR ((coalesce("merchants"."email"::text, '') || ' ' || coalesce("merchants"."company_name"::text, '') || ' ' || coalesce("merchants"."first_name"::text, '') || ' ' || coalesce("merchants"."last_name"::text, '')) % '[email protected]')) AND "merchants"."state" IN ('subscribed', 'in_trial', 'tester', 'trial_ended', 'canceled', 'suspended') AND (sign_in_count > 0)

new query from 0.7.8 looks like

SELECT COUNT("merchants".*, ((ts_rank((setweight(to_tsvector('simple', coalesce("merchants"."email"::text, '')), 'A') || setweight(to_tsvector('simple', coalesce("merchants"."company_name"::text, '')), 'B') || setweight(to_tsvector('simple', coalesce("merchants"."first_name"::text, '')), 'C') || setweight(to_tsvector('simple', coalesce("merchants"."last_name"::text, '')), 'D')), (to_tsquery('simple', ''' ' || '[email protected]' || ' ''')), 0))) AS pg_search_rank) FROM "merchants" WHERE (((setweight(to_tsvector('simple', coalesce("merchants"."email"::text, '')), 'A') || setweight(to_tsvector('simple', coalesce("merchants"."company_name"::text, '')), 'B') || setweight(to_tsvector('simple', coalesce("merchants"."first_name"::text, '')), 'C') || setweight(to_tsvector('simple', coalesce("merchants"."last_name"::text, '')), 'D')) @@ (to_tsquery('simple', ''' ' || '[email protected]' || ' ''')))) AND "merchants"."state" IN ('subscribed', 'in_trial', 'tester', 'trial_ended', 'canceled', 'suspended') AND (sign_in_count > 0))

My model looks like:

class Merchant < ActiveRecord::Base

    include PgSearch

   #creates a search method on the product model
  pg_search_scope :search, against: [
     [:email, 'A'],
     [:company_name, 'B'],
     [:first_name, 'C'],
     [:last_name, 'D'],
  ], :using => {
                  :tsearch => {:prefix => true},
                  :trigram => {}
                }
psql --version
psql (PostgreSQL) 9.3.2

Is this a pg_search bug or an activerecord 4.2 bug?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions