繁体   English   中英

Postgres:根据插入或删除的新记录更新表排序

[英]Postgres: Update table sorting on new record inserted or removed

每次添加(或删除或更新)新记录时,我都试图按指定行自动对表进行排序。

为此,我创建了一个 function

CREATE FUNCTION pid_cluster_function() 
   RETURNS TRIGGER 
   LANGUAGE PLPGSQL
AS $$
BEGIN
   -- trigger logic
     
     cluster verbose public.pid using pid_idx;
END;
$$

并添加触发器


CREATE trigger pid_cluster_trigger 
    after INSERT or update or DELETE on public.pid  
    FOR EACH row  
    execute procedure pid_cluster_function();

但是添加了一条记录

INSERT INTO public.pid (pid,pid_name) VALUES ('111','new 111');

我收到了这样的错误

SQL Error [55006]: ERROR: cannot CLUSTER "pid" because it is being used by active queries in this session
  Where: SQL statement "cluster verbose public.pid using pid_idx"
PL/pgSQL function pid_cluster_function() line 5 at SQL statement

这个错误的原因是什么? 或者是否可以通过其他方式添加或修改记录来实现排序?

好的,谢谢大家,评论区。 我看我的想法不聪明 =)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM