postgres 使用函式批量分段刪除

2021-08-24 17:30:10 字數 1030 閱讀 6102

一、 postgres使用函式批量刪除資料萬級資料

create or replace function del_logs_datas() returns text as 

$$ declare

b_count int;

begin

b_count := 10;

while b_count > 0 loop

delete from logs where time in (select time from logs limit 900000 offset 0);

b_count := b_count - 1;

end loop;

return '刪除成功!';

end;

$$language plpgsql;

-- 執行分段批量刪除

select del_logs_datas();

二 、 postgres使用函式批量插入資料

create or replace function insert_many() returns text as 

$$ declare

r int;

b_count int;

insert_name varchar;

begin

b_count := 22222;

while b_count < 22299 loop

r := (random() * 9000000)::int;

insert into test_effects(id,name) values(b_count,r);

b_count := b_count + 1;

end loop;

return '插入成功';

end;

$$language plpgsql;

-- 執行分段批量刪除

select insert_many();

python資料批量插入postgreSQL資料庫

1 executemany 方法批量輸入資料到資料庫 import pandas as pd import psycopg2 from dbutils.pooleddb import pooleddb import math 批量插入 data 為dataframe資料,size 為批量大小 sql...

postgres簡單使用

次安裝後,會預設生成名為postgres的linux系統使用者 資料庫和資料庫使用者 作為資料庫管理員 首先修改postgres資料庫使用者的密碼,然後增加gerrit需要的資料庫 切換到postgres使用者 sudo su postgres 登入postgres資料庫 psql postgres...

postgres函式(雙重迴圈)

先看基本的語法 namecreate function create or replace function name argmode argname argtype default expr returnsrettype returns table column namecolumn type a...