pgsql 批量插入数据(含数组使用)

postgresql 批量插入数据(含数组使用)

  • postgresql 批量插入数据(含数组使用)

postgresql 批量插入数据(含数组使用)

使用postgreSql 进行批量插入数据,因为有些字段是不能自动生成的,所以使用数组进行循环插入,具体sql如下

do $$
declare 
i integer; -- 定义使用变量
 testArr varchar array; -- 数组定义
begin -- 开始
i :=2200;
testArr := array['张三','李四','王五','六七'];
for index in 1..array_length(testArr, 1) loop -- 循环开始
INSERT INTO public.wares (id,w_name,w_alias,w_unit,w_cost,w_sellprice,w_minnum,w_maxnum,w_description,w_purchase_date,s_id,w_vaild_date,remark,valid_flag,create_date,creator,update_date,updater) VALUES 
(i,testArr[index],testArr[index],'斤',4.000,3.400,20.000,20.000,NULL, now(),NULL,now(),NULL,'1',now(),'管理员',NULL,NULL);
i = i+1;
end loop; -- 循环结束
end $$;

运行完即可插入数据

参考链接:
数据类型-数组
数组构造器
https://www.cnblogs.com/winkey4986/p/6117957.html

你可能感兴趣的:(数据库,postgresql,数组)