【发布时间】:2016-03-20 10:22:26
【问题描述】:
我正在使用 Sequel,并且我有一个带有 JSONB 散列的表作为列,我想从该散列中获取一个值并将其全部存储在表列中。这适用于字符串目标列:
j = Sequel.pg_jsonb_op(:metadata)
DB[:litigation_cached_inputs].update(description: j.get_text('Summary'))
我的诉讼缓存输入表正在更新,以将描述字符串列设置为元数据 JSONB 列中摘要哈希键的值。
当我尝试做同样的事情,但目标列的 (nature_of_suit) 类型是整数时(与此处相反,description 列是字符串类型),我收到错误:
[42] pry(main)> DB[:litigation_cached_inputs].update(nature_of_suit: j.extract('NatureOfSuitID'))
2015-12-14T14:31:23-05:00 [DEBUG] 633 : Sequel::Postgres::Database (3.3ms) UPDATE "litigation_cached_inputs" SET "nature_of_suit" = jsonb_extract_path("metadata", 'NatureOfSuitID')
Sequel::DatabaseError: PG::DatatypeMismatch: ERROR: column "nature_of_suit" is of type integer but expression is of type jsonb
为什么当我想提取一个字符串而不是一个整数时这会起作用?
【问题讨论】:
标签: ruby json postgresql sequel