PG SQL funcation
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();
PG SQL funcation的更多相关文章
- sql差异
类别 MS SQL Server My SQL PG SQL Oracle Access 自增 identity(1,1) auto_increment ALTER TABLE 'tableNam ...
- centos安装postgresql-10及操作
安装postgresql: Linux启动: service postgresql start 创建用户: createuser username 创建数据库: createdb dbname -O ...
- 精读《sqorn 源码》
1 引言 前端精读<手写 SQL 编译器系列> 介绍了如何利用 SQL 生成语法树,而还有一些库的作用是根据语法树生成 SQL 语句. 除此之外,还有一种库,是根据编程语言生成 SQL.s ...
- sqler 集成 terraform v0.12 生成资源部署文件
terraform v0.12 发布了,有好多新功能的添加,包括语法的增强,新函数的引入,更好的开发提示 只是当前对于一些老版本的provider 暂时还不兼容,但是大部分官方的provider 都是 ...
- [转帖]PG语法解剖--基本sql语句用法入门
PG语法解剖--基本sql语句用法入门 https://www.toutiao.com/i6710897833953722894/ COPY 命令挺好的 需要学习一下. 原创 波波说运维 2019-0 ...
- spark sql 查询hive表并写入到PG中
import java.sql.DriverManager import java.util.Properties import com.zhaopin.tools.{DateUtils, TextU ...
- 小麦苗数据库巡检脚本,支持Oracle、MySQL、SQL Server和PG等数据库
目录 一.巡检脚本简介 二.巡检脚本特点 三.巡检结果展示 1.Oracle数据库 2.MySQL数据库 3.SQL Server数据库 4.PG数据库 5.OS信息 四.脚本运行方式 1.Oracl ...
- pg存储过程和sql语句块
展E宝项目使用的是postgresql数据库,批量发送红包需求,需要采用存储过程来初始化红包记录数据. 创建存储过程语句有固定的架子,如下 CREATE OR REPLACE FUNCTION pub ...
- pg 和sql server 分别如何新建二进制数据库字段以及插入二进制数据的sql语句
PG create table demo ( id int, name bytea ); Insert into demo (id,name)values(256,pg_read_binary_fil ...
随机推荐
- java和c# md5加密
MD5加密的方式有很多,加盐的方式更多,最近项目需要java和c#加密结果一致,形成方法如下: 1.c#加密方法/// <summary> /// MD5 加密字符串 /// </s ...
- npm WARN deprecated fsevents windows
更新下 使用yarn貌似会帮助跳过这个问题: info fsevents@2.1.2: The platform "win32" is incompatible with this ...
- flutter chip标签组件
//一个Material widget. 它可以将一个复杂内容实体展现在一个小块中,如联系人.import 'package:flutter/material.dart'; class ChipDem ...
- osg gis编译日志
1>------ 已启动全部重新生成: 项目: ZERO_CHECK, 配置: Debug x64 ------1> Checking Build System1> CMake do ...
- Apache使用内置插件mod_php解析php的配置
apache安装完毕之后,修改httpd.conf配置文件,添加代码如下: LoadModule php5_module modules/libphp5.so <FilesMatch \.php ...
- .Net MVC 标签页
目录 Bootstrap的标签页 适合.Net MVC的标签页 Bootstrap的标签页 下面是Bootstrap的标签页,挺好的,但是用的id,内容是固定的?我不知道怎么变成不同的视图来 < ...
- CSS3动画框架 Animate.css
CSS3的动画应用越来越多了,Animate.css一个从名字上就知道干什么的动画框架. github上的访问地址:http://daneden.github.io/animate.css/ 使用方法 ...
- jvm(5)---垃圾回收(回收算法和垃圾收集器)
1.垃圾回收算法 1.1 标记-清除算法 算法分为“标记”和“清除”阶段:首先标记出所有需要回收的对象,在标记完成后统一回收所有被标记的对象.它是最基础的收集算法,效率也很高,但是会带来两个明显的问题 ...
- ecshop中常用的sql语句
1.获取单条记录 $row = $GLOBALS['db']->getRow($sql); 2.获取单一字段 $row = $GLOBALS['db']->getOne($sql); 查询 ...
- 使用Wifi pineapple(菠萝派)进行Wi-Fi钓鱼攻击
简介: WiFi Pineapple 是由国外无线安全审计公司Hak5开发并售卖的一款无线安全测试神器. 特性: 用作 Wi-Fi 中间人攻击测试平台 一整套的针对 AP 的渗透测试套件 基于 WEB ...