Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 在Rails中订购Postgres jsonb_Ruby On Rails_Postgresql_Jsonb - Fatal编程技术网

Ruby on rails 在Rails中订购Postgres jsonb

Ruby on rails 在Rails中订购Postgres jsonb,ruby-on-rails,postgresql,jsonb,Ruby On Rails,Postgresql,Jsonb,我试图通过rails中的jsonb列使用以下命令进行排序: Stat.order("data ->'likes'->'followed_by' ASC") 我一直得到这个错误的返回 PG::UndefinedFunction: ERROR: could not identify an ordering operator for type json 我搞不懂这是我的格式吗?属性后面的_是一个int 谢谢大家! 我不确定,但根据 ->“获取JSON对象字段” ->“以文本形式获取J

我试图通过rails中的jsonb列使用以下命令进行排序:

Stat.order("data ->'likes'->'followed_by' ASC")
我一直得到这个错误的返回

PG::UndefinedFunction: ERROR:  could not identify an ordering operator for type json
我搞不懂这是我的格式吗?属性后面的_是一个int


谢谢大家!

我不确定,但根据

  • ->
    “获取JSON对象字段”
  • ->
    “以文本形式获取JSON对象字段”
  • 因此,activerecord可能无法对
    字段进行排序,但可以对
    文本进行排序


    尝试:
    Stat.order(“数据->'likes'->>”,后跟'ASC”)

    ,供其他人查找;我需要在jsonb字段中按日期排序。使用“my_column->'date'DESC”返回一个文本对象。这是因为日期格式为“YYYY-MM-DD”。但是我使用了对象符号,它作为一个实际的日期:“my_column->>‘date’DESC”