Stored procedures 删除自当前时间起2个月前最新访问的红移表

Stored procedures 删除自当前时间起2个月前最新访问的红移表,stored-procedures,amazon-redshift,Stored Procedures,Amazon Redshift,下面是试图删除过去2个月内未访问的表的存储_过程 CREATE OR REPLACE PROCEDURE sp_drop_tables(out_var OUT varchar(256)) -- CREATE OR REPLACE PROCEDURE sp_drop_tables_() AS $$ DECLARE r_c int := 0; rec record; tbl_rows int; BEGIN for rec in select distinct table_name f

下面是试图删除过去2个月内未访问的表的存储_过程

CREATE OR REPLACE PROCEDURE sp_drop_tables(out_var OUT varchar(256))
-- CREATE OR REPLACE PROCEDURE sp_drop_tables_()
AS $$
DECLARE
 r_c int := 0;
 rec record;
 tbl_rows int;
BEGIN   
  for rec in select distinct table_name from information_schema.tables
  loop
      raise info 'table_name = %', rec.table_name;
      tbl_rows := 0;
      select count(*) into tbl_rows from admin.stl_query_archive where endtime > getdate() - 61 and querytxt like '%'||quote_literal(rec.table_name)||'%';
      if tbl_rows = 0 then
        raise info 'this table is old';
      end if;
  end loop;
  select into out_var count(*) from admin.stl_query_archive;
END;
$$ LANGUAGE plpgsql;

call sp_drop_tables()
;
Information_schema.tables包含红移集群中存在的所有表。admin.stl_query_archive包含迄今为止运行的所有查询

我正在尝试查找过去2个月内运行的查询中不存在的所有表

CREATE OR REPLACE PROCEDURE sp_drop_tables(out_var OUT varchar(256))
-- CREATE OR REPLACE PROCEDURE sp_drop_tables_()
AS $$
DECLARE
 r_c int := 0;
 rec record;
 tbl_rows int;
BEGIN   
  for rec in select distinct table_name from information_schema.tables
  loop
      raise info 'table_name = %', rec.table_name;
      tbl_rows := 0;
      select count(*) into tbl_rows from admin.stl_query_archive where endtime > getdate() - 61 and querytxt like '%'||quote_literal(rec.table_name)||'%';
      if tbl_rows = 0 then
        raise info 'this table is old';
      end if;
  end loop;
  select into out_var count(*) from admin.stl_query_archive;
END;
$$ LANGUAGE plpgsql;

call sp_drop_tables()
;
我的方法似乎是正确的,唯一的问题是它在运行时抛出以下错误-

    Error [XX000 / 500310]: [Amazon](500310) Invalid operation: Assert 
----------------------------------------------- error: Assert code: 1000 context: false - Unknown 
constant type to hash: 17134 query: 2122914 location: cg_hash.cpp:84 process: padbmaster [pid=124705] 
-----------------------------------------------;

有人能帮我解决这个问题吗?非常感谢您的反馈

我认为您不需要在类似条件中使用quote\u literal函数。

过程中的哪一行生成了错误?