我在我的表上设置了一个触发器来使用dblink更新插入的行。我使用dblink是因为想要触发器来更新行异步。
我已成功测试了pgAdmin SQL查询工具中的dblink更新。但是,当我插入一行时,触发器会运行,但不会更新任何行。
对于dblink,我有什么遗漏吗?
CREATE OR REPLACE FUNCTION locates_data.async_update_geom()
RETURNS trigger AS
$BODY$
BEGIN
-- as this is an after trigger, NEW contains all the information we need even for INSERT
perform dblink('dbname=devtable00 host=10.1.1.98 port=5432 user=admin password=*****', 'update locates_data.request set geom = ST_Transform(ST_setSRID(ST_MakePoint('||NEW.longitude||','||NEW.latitude||'), 4326),3857) where request_pk = '||NEW.request_pk||'');
RAISE NOTICE 'UPDATING geo data for %, [%,%]' , NEW.request_pk, NEW.latitude, NEW.longitude;
RETURN NEW; -- result is ignored since this is an AFTER trigger
END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION locates_data.async_update_geom()