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

PostgreSQL更新表时出现integer类型输入语法无效错误求助

问题原因与解决方法

错误核心是你在PL/pgSQL函数的UPDATE语句里,把**字符串字面量'@vendortypeid'**赋值给了integer类型的vendortypeid字段,PostgreSQL无法将这个字符串转成整数,所以抛出22P02类型转换错误。

解决步骤:

  • 直接使用函数定义的参数名,不要加@符号和单引号。比如函数参数里的integer类型参数(对应vendortypeid字段),直接写vendortypeid = 参数名。
  • 所有字段都遵循这个规则:boolean、date、bigint等类型的字段,直接绑定参数,不要用字符串包裹。
  • 确保WHERE子句里的vendorids是函数的有效参数。

修正后的UPDATE语句示例(假设函数参数名和字段名一致,若冲突可给参数加前缀如p_):

update public.vendormaster vm
set vendortypeid = vendortypeid,
    email = email, 
    misbapsid = misbapsid, 
    businessname = businessname, 
    taxid = taxid, 
    primarycontactname = primarycontactname, 
    primarycontactemail = primarycontactemail, 
    additionalname = additionalname, 
    primaryaddress1 = primaryaddress1, 
    primaryaddress2 = primaryaddress2, 
    primarycountryid = primarycountryid, 
    primarystateid = primarystateid, 
    primaryzipcode = primaryzipcode, 
    ischild = ischild, 
    parentid = parentid, 
    isactive = isactive, 
    mobileno = mobileno,
    createdby = createdby,
    createdon = createdon, 
    isdeleted = isdeleted, 
    deletedby = deletedby, 
    deletedon = deletedon, 
    updatedby = updatedby,
    updatedon = updatedon, 
    primarycityid = primarycityid, 
    status = status
where vm.vendorid = vendorids;

额外提示:

如果函数参数名和表字段名完全相同,为避免歧义,可以在参数前加上函数名限定,比如insertorupdatevendormaster.vendortypeid,或者定义参数时就加前缀(比如p_vendortypeid),这样语句更清晰:

update public.vendormaster vm
set vendortypeid = p_vendortypeid,
    email = p_email,
    -- 其他字段同理
where vm.vendorid = p_vendorids;

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.08 00:45:31