删除ADcompiere一个实体postgresql脚本

/**
* PostgresSQL Client remove function
*
* Use to remove a client from ADempiere, e.g. remove GardenWorld
*
* ///
* WARNING: This function works fine with my current setup. Yours
* may be different so backup your database before using!
* I am not responsible for any problems this may cause.
* ///
*
* - Usage:
* 1. Install drop_client function (Run this script)
* 2. Run the following sql:
* SELECT <db_name>.drop_client(<db_name>, <client_id>);
* e.g. SELECT adempiere.drop_client('adempiere', 11); --> Removes GardenWorld
*
* -Credits:
* Credits due to Fernando Lucktemberg(fer_luck) for the main workings
* Credit to the guys @ e-Nition.com for improving it :)
*/
CREATE OR REPLACE FUNCTION adempiere.drop_client(db_name text, client_id integer)
RETURNS integer AS
$BODY$
DECLARE
db_name text := $1;
c_id integer := $2;
tmp RECORD;
BEGIN
RAISE NOTICE 'Setting search_path=%', db_name;
EXECUTE 'SET search_path='
|| db_name;
RAISE NOTICE 'Deleting %.Client Where AD_Client_ID=%', db_name, c_id;
RAISE NOTICE 'Disable triggers & constraints';
update pg_trigger set tgenabled = '0' where oid in (
select tr.oid from pg_class cl, pg_trigger tr
where cl.relnamespace = 527568
and tr.tgrelid = cl.oid);
RAISE NOTICE 'Removing records belonging to client %', c_id;
FOR tmp IN
select * from ad_table t where isview = 'N'
and ad_table_id in (select ad_table_id from ad_column where columnname = 'AD_Client_ID')
order by tablename
LOOP
raise notice 'Removing items from table - %', tmp.tablename;
EXECUTE 'DELETE FROM ' || tmp.tablename || ' WHERE AD_Client_ID = ' || c_id;
END LOOP;
RAISE NOTICE 'Enable triggers & constraints';
update pg_trigger set tgenabled = '0' where oid in (
select tr.oid from pg_class cl, pg_trigger tr
where cl.relnamespace = 527568
and tr.tgrelid = cl.oid);
RAISE NOTICE 'Done';
RETURN 1;
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE
COST 100;
ALTER FUNCTION adempiere.drop_client(text, integer) OWNER TO postgres;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值