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 ...
随机推荐
- 2019年逾期率上升_24家头部P2P平台最新运营数据解读:8家近一年逾期率走势曝光
python信用评分卡建模(附代码,博主录制) https://study.163.com/course/introduction.htm?courseId=1005214003&utm_ca ...
- Sword cjson库函数使用
/* cjson库的使用 */ #include <stdio.h> #include <stdlib.h> #include <string.h> #includ ...
- 全面系统Python3入门+进阶-1-3 我为什么喜欢Python
结束
- Spring cloud微服务安全实战-3-3 API安全机制之流控
首先要保证你的服务是可用的,其中一个重要的手段就是流控.就是流量控制.比如我的系统每秒只能处理500个请求,那么多余的请求就拒绝掉.这样我的系统不会被压死 实际的开发中,所要面对的流控场景实际是非常复 ...
- django 中单独执行py文件修改用户名
Python文件代码 import os import django # 在environ字典里设置默认Django环境,'xxxx.settings'指Django项目的配置文件 os.enviro ...
- mybatis typeHandler类型转换器
typeHandler类型转换器 在JDBC中,需要在PreparedStatement对象中设置那些已经预编译过的SQL语句的参数.执行SQL后,会通过ResultSet对象获取得到数据库的数据,而 ...
- AnyCAD三维控件(转)
在WinForm中可以方便的集成AnyCAD.Net三维控件,只需要以下几部即可完成. 一.添加DLL程序集 AnyCAD.Foundation.Net.dll AnyCAD.Presentation ...
- Nginx配置自定义的403页面
1.开启nginx的状态码,虚拟主机配置中加入下边一段 location /nginx_status{ stub_status on; access_log off; } 或着在nginx的http模 ...
- Java连接MongoDB报错“java.lang.IllegalArgumentException: clusterListener can not be null”的解决办法
我使用的MongoDB版本是3.6.9. 下面是一个很基础的示例代码,功能就是连接MongoDB: package com.zifeiy.snowflake.handle.etl.mongodb; i ...
- 使用sql语句创建和删除约束示例代码
使用sql语句创建和删除约束 约束类型 主键约束(Primary Key constraint) --:要求主键列数据唯一,并且不允许为空. 唯一约束(Unique constraint) --: ...