使用Supabase Python更新表时遇PGRST104错误:解析过滤器失败
解决Supabase Python库更新操作中的PGRST104错误
你遇到的postgrest.exceptions.APIError(错误码PGRST104)是因为过滤条件解析失败,错误信息Failed to parse [("id","Filters.EQ.1")]表明请求中的过滤器格式不符合PostgREST要求。你的测试代码如下:
updatedtime = str(datetime.now()+timedelta(seconds=10)) update = sb.table("schedule").update({"scheduled_time": updatedtime}).eq("id", 1).execute() if update: print("updated schedule!") else: print("L")
解决方案
调整过滤条件写法:
将.eq("id", 1)替换为.match({"id": 1}),这种单字段精确匹配的写法更直观,可避免操作符解析异常:update = sb.table("schedule").update({"scheduled_time": updatedtime}).match({"id": 1}).execute()验证字段类型匹配:
确认schedule表的id字段类型与传入的1一致(比如id为整数类型而非字符串),类型不匹配也会引发过滤器解析问题。优化时间格式(附加修复):
当前用str()转换datetime对象的格式可能不符合PostgreSQLtimestamp字段要求,建议改用isoformat()生成标准时间字符串,避免后续时间解析错误:updatedtime = (datetime.now() + timedelta(seconds=10)).isoformat()更新Supabase客户端版本:
若参考的教程使用旧版supabase-py,可能存在API差异。执行以下命令更新到最新版本:pip install --upgrade supabase
内容的提问来源于stack exchange,提问作者dangather
相关产品推荐
相关产品推荐

