使用Prisma更新数据报错:get_xmlbinary()函数不存在求助
Prisma更新数据时触发PostgreSQL函数错误:get_xmlbinary()不存在
问题场景
通过Prisma以唯一ID更新custom_checkout__c表的部分字段时触发错误,此前查询表数据功能正常。
执行的更新代码
const cartUpdate = await prisma.custom_checkout__c.update({ where: { id: uniqueId, }, data: { status__c: 'Checkout completed', coupon_code__c: coupon, checkout_id__c: result.subscription.id, } })
触发的错误信息
PrismaClientUnknownRequestError: Invalid `prisma.custom_checkout__c.update()` invocation: Error occurred during query execution: ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(Error { kind: Db, cause: Some(DbError { severity: "ERROR", parsed_severity: Some(Error), code: SqlState(E42883), message: "function get_xmlbinary() does not exist", detail: None, hint: Some("No function matches the given name and argument types. You might need to add explicit type casts."), position: Some(Internal { position: 2, query: "(get_xmlbinary() = 'base64')" }), where_: Some("PL/pgSQL function hc_custom_checkout__c_status() line 3 at IF"), schema: None, table: None, column: None, datatype: None, constraint: None, file: Some("parse_func.c"), line: Some(629), routine: Some("ParseFuncOrColumn") }) }) }) at RequestHandler.handleRequestError (/Users/bi
错误核心:get_xmlbinary()函数不存在,问题出在PL/pgSQL函数hc_custom_checkout__c_status()的第3行IF语句处。
问题分析
这个错误和Prisma代码本身无关,是数据库层面的问题:
- 更新
status__c字段时,数据库中关联的hc_custom_checkout__c_status()函数被触发,该函数内部调用了get_xmlbinary(),但这个函数在当前PostgreSQL环境中不存在 get_xmlbinary()一般是PostgreSQL的xml2扩展提供的函数,大概率是该扩展未安装,或者自定义的get_xmlbinary()函数被误删除
解决方案
- 检查并安装xml2扩展
登录PostgreSQL数据库,执行以下SQL命令:
-- 先检查xml2扩展是否已安装 SELECT * FROM pg_extension WHERE extname = 'xml2'; -- 如果没安装,执行安装 CREATE EXTENSION IF NOT EXISTS xml2;
修复自定义函数
如果get_xmlbinary()是自定义函数,先确认它是否存在,若不存在则重新创建;或者直接修改hc_custom_checkout__c_status()函数的逻辑,替换掉对get_xmlbinary()的调用。验证修复
手动在数据库中执行更新语句测试,确认函数能正常运行后,再重新执行Prisma的更新代码。
内容的提问来源于stack exchange,提问作者Bilal Rabbi
相关产品推荐
相关产品推荐

