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

PostgreSQL中如何将bigint列数据复制到bigint[]列?

解决方案:将单个bigint值复制到bigint数组列

你之前的SQL语句存在两个问题:

  • 赋值方向颠倒了,应该是把customerId的值赋给customerIds,而非反过来
  • 没有将单个bigint值转换为bigint[]数组类型

PostgreSQL中可以使用ARRAY[]构造器将单个值包装成单元素数组,执行以下语句即可完成需求:

UPDATE table_name
SET customerIds = ARRAY[customerId];

如果需要明确指定数组类型(避免潜在的类型歧义),可以加上类型转换:

UPDATE table_name
SET customerIds = ARRAY[customerId]::bigint[];

若只想更新customerId不为空的行,可添加WHERE条件过滤:

UPDATE table_name
SET customerIds = ARRAY[customerId]
WHERE customerId IS NOT NULL;

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.13 06:15:31