PG bulk delete table

By using stored procedures way to batch delete tables
Create or replace function procedure name (parameter type parameter name, ......) returns as the return value type b O d Y body

具体应用:删除public用户下的所有表
CREATE FUNCTION del_ora_table() RETURNS void AS $$
DECLARE
tmp VARCHAR(512);
DECLARE names CURSOR FOR
select tablename from pg_tables where schemaname=‘public’;
BEGIN
FOR stmt IN names LOOP
tmp := 'DROP TABLE ‘|| quote_ident(stmt.tablename) || ’ CASCADE;’;
RAISE NOTICE ‘notice: %’, tmp;
EXECUTE 'DROP TABLE ‘|| quote_ident(stmt.tablename) || ’ CASCADE;’;
END LOOP;
RAISE NOTICE ‘finished …’;
END;

$$ LANGUAGE plpgsql;

- Perform batch delete function table
select del_ora_table ();

Published 75 original articles · won praise 7 · views 10000 +

Guess you like

Origin blog.csdn.net/zhengdong12345/article/details/102918978