last_vals :=''; -- 旧值,text
-- 保存旧数据,备修改后对照查询
with h as (select id,... from aa where ...)
,h1 as (select id,... from h) -- 过滤查询1
,h2 as (select from h1) --处理
select array_agg(hstore(h2))::text into last_vals from h2; -- 转换成text临时保存
raise notice 'last=%',last_vals::text;
--- 此处是若干更新操作
-- 对照旧数据,更新记录
with h as (select last_vals as vals)
,h1 as (select unnest(vals::hstore[]) val from h) -- 转换成hstore
,h2 as (select res.* from h1,populate_record(null::aa,h1.val) res) -- 将text转换成 record set, aa 为表名
,h3 as (select ...... from h2 , aa where ...) -- 继续查询
,up as (update aa d set ... from h3 where ... returning ...) -- 更新
select array_agg(hstore(up))::text into last_vals from up;
raise notice 'new=%',last_vals::text;