PG SQL funcation
2024-08-27 05:04:28
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();
最新文章
- 使用Android Butterknife
- Mysql 行列转换
- GetDlgItem
- javaBean与Map<;String,Object>;互转
- 【故障处理】CRS-1153错误处理
- bzoj-3444 3444: 最后的晚餐(组合数学)
- JVM垃圾收集策略解析
- php--yii2.0框架的curl
- 安装centos7.1 32bit时,没有可用的网络设备的解决方法
- git push 提示
- WebBench简介
- Struck: Structrued Output Tracking with Kernels 论文笔记
- Linux学习笔记总结--配置iptables防火墙
- 基本数据类型的常量池与String类型常量池解析
- springMVC整合jedis+redis,以注解形式使用
- 【学习笔记】【Foundation】数组
- WinForm 控件不闪烁
- find -exec
- 小猪猪逆袭成博士之C++基础篇(一)数据精度、强制类型转换、变量命名规则
- G - 小希的迷宫(并查集)
热门文章
- centos6.8安装python3.7.3报错Can&#39;t connect to HTTPS URL because the SSL module is not available问题解决
- Scala里面的排序函数的使用
- Fiddler抓包显示请求时延
- @media 适配兼容
- vue react 路由history模式刷新404问题解决方案
- Tools - Summary List
- github账户初始化设置
- 【网络开发】UDP组播接收端解析
- Qt5.编译错误.error: C2338: The slot requires more arguments than the signal provides.
- axios.js 在测试机ios7.1的iphone4中不能发送http请求解决方案