首页 > 解决方案 > Ruby on Rails PG::InvalidTextRepresentation: ERROR: malformed array literal

问题描述

我有下表配置文件与 jsonb 列

物品种类 object_changes
“物品” [{"customer_id": [1, 5], "other_id": 1}, {"customer_id": [4, 5], "other_id": 2}]
“物品” [{"customer_id": [3, 6], "other_id": 3}, {"customer_id": [3, 5], "other_id": 2}]

我有以下查询解决方案

SELECT distinct profiles.*
FROM 
  profiles, 
  jsonb_to_recordset(profiles.object_changes) AS changes(customer_id integer[], other_id integer)
WHERE 5 = ANY(changes.customer_id);

但是当我运行我的代码时,我得到了这个错误

ActiveRecord::StatementInvalid:
       PG::InvalidTextRepresentation: ERROR:  malformed array literal: "[1, 5]"
       DETAIL:  Missing "=" after array dimensions.
       : SELECT distinct profiles.*
       FROM
         profiles,
         jsonb_to_recordset(profiles.object_changes) AS changes(customer_id integer[], other_id integer)
WHERE '5' = ANY(changes.customer_id);

我该如何解决这个问题?

标签: sqlrubypostgresqlruby-on-rails-4jsonb

解决方案


推荐阅读