Error: PG::Error: ERROR: column "pg_search_rank" does not exist #110

gregolsen opened this Issue Apr 11, 2013 · 11 comments


5 participants

pg_search 0.6.1 fails to build a query when includes used and dot is present in the string

My model config:

pg_search_scope :full_text_search,
                against: :content,
                using: { tsearch: {prefix: true} }




Error: PG::Error: ERROR:  column "pg_search_rank" does not exist

Looks like this bug was present before and was fixed #14

And see issue #109 for what appears to be a bug that is triggered by the fix of #14.

I'm getting this same error as well.

scope :public_view, includes(:status).where("inventory_statuses.code in ('S','V','R','P','D','C') AND machines.is_active = true AND machines.show_on_web = true")

The scope works fine if I switch the includes to joins. Any ideas?

@hallmatt, work-around is to create your left joins manually instead of relying on includes.
Something like: Machine.joins('LEFT OUTER JOIN status ON status.machines_id =').where . . .

@chuckweinberger this workaround will work only if you want to filter data but if you want to load associations and access them later on you still need includes

Thanks @gregolsen. Includes is necessary in the case, as I'm using the associations and data later on in the views. Anyway we can get a fix for this issue?

@gregolsen, true, but as @maxwell pointed out in #109, you can combine the joins with ActiveRecord#preload so to actively load the associations without using includes.

@chuckweinberger thanks for pointing that out!


Thanks @gregolsen and @chuckweinberger for the workaround of preload and joins. Hopefully this issue can be resolve soon. Here's code of how I use it

@users = User
  .joins("left outer join companies ON = users.company_id")
  .page params[:page]

nertzy commented May 14, 2015

Closing this because pg_search 1.0 uses a different strategy to build the query. Please open a new issue if you have problems going forward.

@nertzy nertzy closed this May 14, 2015

hallmatt commented Sep 2, 2015

I've upgraded to 1.x and am still getting this issue. At first I thought it was related to large results being returned, but I have an example where only one result is returned. Here's the full line of code I'm using:

search(keywords).reorder('pg_search_rank DESC')`

If I walk through the issue with a debugger, I can get one result using the search function:


but as soon as I tack on the reorder function, I get a hard crash

search(keywords).reorder('pg_search_rank DESC')`
INTERNAL ERROR!!! PG::UndefinedColumn: ERROR:  column "pg_search_rank" does not exist
LINE 1: ...arch_id WHERE "machines"."tenant_id" = 1 ORDER BY pg_search_...

hallmatt commented Sep 2, 2015

It looks like it works fine with multisearch, but not on the individual model search

Individual Model Search Options:

  pg_search_scope :search,
                  :against => [:model_description, :stock_order_number, :serial_number, :year, :hours, :total_price, :stick_length, :pad_width, :transmission_type, :tires, :attachments, :two_or_four_wheel_drive, :bucket_size, :other, :cab2_rops, :app_weight, :comments, :description, :category_name, :make_name, :notes],
 :using => {
              :tsearch => {
                :prefix => true,  # otherwise only matches whole words
                :dictionary => "english"  # enables 'stemming' features e.g. jump, jumped, jumper
              :trigram => {:threshold => 0.3}

Multisearch Options

PgSearch.multisearch_options = {
  :using => {
              :tsearch => {
                :prefix => true,  # otherwise only matches whole words
                :dictionary => "english"  # enables 'stemming' features e.g. jump, jumped, jumper
              :trigram => {:threshold => 0.3}

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