错误:无法识别 json 类型的相等运算符

ERROR: could not identify an equality operator for type json

提问人:Mathieu 提问时间:9/26/2023 最后编辑:Laurenz AlbeMathieu 更新时间:9/26/2023 访问量:43

问:

我收到错误ERROR: could not identify an equality operator for type json

启动 SQL 查询时

update pdfs
set forced_payload = datatable.forced_payload,
    s3_original_path = datatable.s3_original_path,
    s3_image_path = datatable.s3_image_path,
    s3_preview_path = datatable.s3_preview_path,
    s3_original_inbox_path = datatable.s3_original_inbox_path,
    s3_preview_inbox_path = datatable.s3_preview_inbox_path
from (select 43238::integer as id,
             NULL::json as forced_payload,
             NULL::character varying(255) as s3_original_path,
             NULL::character varying(255) as s3_image_path,
             NULL::character varying(255) as s3_preview_path,
             NULL::character varying(255) as s3_original_inbox_path,
             NULL::character varying(255) as s3_preview_inbox_path
      union
      select 43239,
             NULL,
             NULL,
             NULL,
             NULL,
             NULL,
             NULL
     ) as datatable
where pdfs.id = datatable.id;

针对 postregSQL 数据库

我不知道为什么会出现此错误。 我看过其他有此错误的帖子,但它们与此处的使用有关,或者此处并非如此。DISTINCTGROUP_BY

更多背景信息:

我有一个带有 gem bulk_data_methods的 rails 项目,以便仅使用一个 DB 查询更新 DB 中的多条记录。

这是创建上述数据库查询的 Gem。

(Rails 中的完整错误是:ActiveRecord::StatementInvalid: PG::UndefinedFunction: ERROR: could not identify an equality operator for type json)

sql json ruby-on-rails PostgreSQL

评论


答:

1赞 Laurenz Albe 9/26/2023 #1

问题可能出在.为了计算,PostgreSQL必须删除重复项,如果没有平等的概念,它就无法做到这一点。使用 ,则 PostgreSQL 不会尝试删除重复项。UNIONUNIONUNION ALL

评论

0赞 Mathieu 9/26/2023
谢谢!这是问题和正确的解决方案(使用)(我只需要确保自己没有重复)UNION ALL