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/

PG SQL funcation的更多相关文章

  1. sql差异

    类别 MS SQL Server My SQL PG SQL Oracle Access  自增  identity(1,1) auto_increment ALTER TABLE 'tableNam ...

  2. centos安装postgresql-10及操作

    安装postgresql: Linux启动: service postgresql start 创建用户: createuser username 创建数据库: createdb dbname -O ...

  3. 精读《sqorn 源码》

    1 引言 前端精读<手写 SQL 编译器系列> 介绍了如何利用 SQL 生成语法树,而还有一些库的作用是根据语法树生成 SQL 语句. 除此之外,还有一种库,是根据编程语言生成 SQL.s ...

  4. sqler 集成 terraform v0.12 生成资源部署文件

    terraform v0.12 发布了,有好多新功能的添加,包括语法的增强,新函数的引入,更好的开发提示 只是当前对于一些老版本的provider 暂时还不兼容,但是大部分官方的provider 都是 ...

  5. [转帖]PG语法解剖--基本sql语句用法入门

    PG语法解剖--基本sql语句用法入门 https://www.toutiao.com/i6710897833953722894/ COPY 命令挺好的 需要学习一下. 原创 波波说运维 2019-0 ...

  6. spark sql 查询hive表并写入到PG中

    import java.sql.DriverManager import java.util.Properties import com.zhaopin.tools.{DateUtils, TextU ...

  7. 小麦苗数据库巡检脚本,支持Oracle、MySQL、SQL Server和PG等数据库

    目录 一.巡检脚本简介 二.巡检脚本特点 三.巡检结果展示 1.Oracle数据库 2.MySQL数据库 3.SQL Server数据库 4.PG数据库 5.OS信息 四.脚本运行方式 1.Oracl ...

  8. pg存储过程和sql语句块

    展E宝项目使用的是postgresql数据库,批量发送红包需求,需要采用存储过程来初始化红包记录数据. 创建存储过程语句有固定的架子,如下 CREATE OR REPLACE FUNCTION pub ...

  9. pg 和sql server 分别如何新建二进制数据库字段以及插入二进制数据的sql语句

    PG create table demo ( id int, name bytea ); Insert into demo (id,name)values(256,pg_read_binary_fil ...

随机推荐

  1. TypedValue: 使用TypedValue将dip值转换成px值

    之前自己一直手工编写函数来实现dip值到px值,今天无意中发现android本身就带有类似的函数来实现这种转换过程,就是 TypedValue.applyDimension public class ...

  2. ffmpeg-php扩展

    php视频缩略图,较常用的是ffmpeg-php 1: 安装 ffmpeg ffmpeg的下载链接  http://ffmpeg.org/download.html 解压安装包 tar -jxvf f ...

  3. 禁止select标签选择,禁止select组件change值

    大家知道, 对于HTML控件select, 是没有readOnly属性的,所以设置它并不起作用,如: 如果用disabled的话,提交时又取不到值. 那有什么方法可以实现?可以有一个折中的方法,如下: ...

  4. Ionic app IOS 在Xcode 模拟运行 真机调试

    1. 创建项目: sudo ionic start myApp tabs 2 cd 到刚才创建的项目 3. sudo ionic cordova platform add ios 把 ios 环境添加 ...

  5. 【转载】 准人工智能分享Deep Mind报告 ——AI“元强化学习”

    原文地址: https://www.sohu.com/a/231895305_200424 ------------------------------------------------------ ...

  6. 算法习题---5.6团体队列(Uva540)

    一:题目 有t个队伍的人正在排队,每次新来一个人,如果他有队友在排队,那他可以插队,直接排到他的队伍的末尾.如果没有队伍在前面,那么他直接排在长队的末尾 ENQUEUE x 将编号x的队员入队 DEQ ...

  7. Spring 定时任务 注解版

    Task类: ManageSql.Java对应代码: package com.axb.cheney.task; import java.sql.ResultSet; import java.sql.S ...

  8. tensor&ndarray&int、float

    (1)如果tensor只有一个元素,然后转换成int或者float类型的时候直接用int()或者float()就可以了: (2)如果tensor含有多个元素,转换成ndarray时就要用x.detac ...

  9. java使用ffmpeg生成HLS切片文件

    /*** * 将文件切割成片 * @param filename * @param uuid * @param data * @throws IOException */ default void d ...

  10. LeetCode_345. Reverse Vowels of a String

    345. Reverse Vowels of a String Easy Write a function that takes a string as input and reverse only ...