create extension  IF NOT EXISTS "uuid-ossp" ;
--select uuid_generate_v4();
--select current_timestamp; --select * from (select *,row_number() over(partition by merchant_id order by create_time desc) as num from merchants.merchant_money_record) as temp_tb1 where num=1; CREATE OR REPLACE FUNCTION for_loop_through_query(
)
RETURNS VOID AS $$
DECLARE
rec RECORD;
merchantid uuid;
balance NUMERIC;
record_remark VARCHAR;
account_entity_id uuid;
account_id uuid;
transaction_flow_id INT;
transaction_flow_detail_id INT;
transaction_time TIMESTAMP;
BEGIN
DELETE FROM "AccountBook".accounting_entity;
DELETE FROM "AccountBook".account;
DELETE FROM "AccountBook".callback_log;
DELETE FROM "AccountBook".transaction_flow;
DELETE FROM "AccountBook".transaction_flow_detail;
FOR rec IN select * from (select *,row_number() over(partition by merchant_id order by create_time desc) as num from merchants.merchant_money_record) as temp_tb1 where num=1
LOOP
account_entity_id := uuid_generate_v4();
account_id := uuid_generate_v4();
--transaction_flow_id := uuid_generate_v4();
merchantid := rec.merchant_id;
balance := rec.current_amount;
record_remark := rec.record_remark;
transaction_time := rec.transaction_time;
INSERT INTO "AccountBook".accounting_entity ("id","type",system_id) VALUES (account_entity_id,1,merchantid);
INSERT INTO "AccountBook".account ("id","accounting_entity_id","type","balance","createtime","currency_type","status","system_id") VALUES (account_id,account_entity_id,1,balance,current_timestamp,1,1,merchantid);
INSERT INTO "AccountBook".transaction_flow ("type","business_num","occurrence_time","createtime","remark","accounting_entity_id") VALUES (7,record_remark,transaction_time,current_timestamp,'初始化余额',account_entity_id);
transaction_flow_id := currval('"AccountBook".transaction_flow_id_seq');
INSERT INTO "AccountBook".transaction_flow_detail ("transaction_flow_id","account_id","amount","trading_num","current_amount") VALUES (transaction_flow_id,account_id,balance,record_remark,balance);
transaction_flow_detail_id := currval('"AccountBook".transaction_flow_detail_id_seq');
RAISE NOTICE '%||%||%||%||%', merchantid,balance,account_entity_id,transaction_flow_id,transaction_flow_detail_id;
END LOOP;
END;
$$ LANGUAGE plpgsql; select for_loop_through_query();

参考https://pg.sjk66.com/

最新文章

  1. 使用Android Butterknife
  2. Mysql 行列转换
  3. GetDlgItem
  4. javaBean与Map<String,Object>互转
  5. 【故障处理】CRS-1153错误处理
  6. bzoj-3444 3444: 最后的晚餐(组合数学)
  7. JVM垃圾收集策略解析
  8. php--yii2.0框架的curl
  9. 安装centos7.1 32bit时,没有可用的网络设备的解决方法
  10. git push 提示
  11. WebBench简介
  12. Struck: Structrued Output Tracking with Kernels 论文笔记
  13. Linux学习笔记总结--配置iptables防火墙
  14. 基本数据类型的常量池与String类型常量池解析
  15. springMVC整合jedis+redis,以注解形式使用
  16. 【学习笔记】【Foundation】数组
  17. WinForm 控件不闪烁
  18. find -exec
  19. 小猪猪逆袭成博士之C++基础篇(一)数据精度、强制类型转换、变量命名规则
  20. G - 小希的迷宫(并查集)

热门文章

  1. centos6.8安装python3.7.3报错Can't connect to HTTPS URL because the SSL module is not available问题解决
  2. Scala里面的排序函数的使用
  3. Fiddler抓包显示请求时延
  4. @media 适配兼容
  5. vue react 路由history模式刷新404问题解决方案
  6. Tools - Summary List
  7. github账户初始化设置
  8. 【网络开发】UDP组播接收端解析
  9. Qt5.编译错误.error: C2338: The slot requires more arguments than the signal provides.
  10. axios.js 在测试机ios7.1的iphone4中不能发送http请求解决方案