You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Decimal类型仍触发DynamoDB Scan报错‘Float types are not supported’

DynamoDB Scan报错:Float types are not supported的解决办法

你的问题出在time.time()返回的是带小数的浮点数,即便用Decimal()包裹,DynamoDB在解析FilterExpression时,仍会识别到浮点数相关的类型特征,从而触发报错。

解决方法很简单:先将时间计算结果转为整数(因为TTL字段通常存储的是整数时间戳),再转换为Decimal类型:

from decimal import Decimal
import time

# 先计算整数时间阈值,再转Decimal
cutoff_timestamp = Decimal(int(time.time() - 900))
response = table.scan(
    FilterExpression=Attr('ttl').gte(cutoff_timestamp) & Attr('SessionStatus').eq('failed')
)

原理:TTL字段一般存储的是Unix整数时间戳,直接使用整数转Decimal,能完全匹配DynamoDB对数值类型的要求,避免浮点数相关的类型校验问题。

内容的提问来源于stack exchange,提问作者notAChance

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 20:06:01