postgresql 运算符不存在:jsonb = integer

xkrw2x1b  于 11个月前  发布在  PostgreSQL
关注(0)|答案(1)|浏览(125)

我得到以下postgres错误:
“运算符不存在:jsonb = integer”
x1c 0d1x的数据
我的应用程序托管在Heroku上,使用的是Postgres 9.4 DB。下面是我的帐户控制器与ahoy_martey分析gem的外观。

账户管理员

class AccountsController < ApplicationController
  before_filter :authenticate_user!

  def index
    if current_user.business_id
      @business = Business.find(current_user.business_id)
      # analytics
      @monthly_business_views = ahoy_event_sum("Page Viewed", @business.id)
      @monthly_get_websites = ahoy_event_sum("Visited Website", @business.id)
      @monthly_get_directions = ahoy_event_sum("Directions Viewed", @business.id)
      @monthly_get_fb_shares = ahoy_event_sum("Shared via Facebook", @business.id)
      @monthly_get_tweets = ahoy_event_sum("Tweeted via Twitter", @business.id)
      @reviews = Review.where(:business_id => @business).all
    end
  end

  ...

  def ahoy_event_sum(event, business_id)
    Ahoy::Event.where(name:event, properties: business_id).count
  end

end

字符串

Ahoy事件模型

module Ahoy
  class Event < ActiveRecord::Base
    self.table_name = "ahoy_events"

    belongs_to :visit
    belongs_to :user

    serialize :properties, JSON
  end
end


我有中级技能和道歉,如果这个问题有一个简单的修复,请提供任何细节,我将如何解决这个问题。谢谢!

rjee0c15

rjee0c151#

更新查询以直接按properties列过滤,而不是使用serialize方法:

Ahoy::Event.where(name: event, properties: { business_id: business_id }).count

字符串
serialize方法不是必需的,因为properties列已经是JSONB列,这是PostgreSQL中的本地序列化类型:

# serialize :properties, JSON

相关问题