stored-procedures - 删除距当前时间 2 个月前最近访问的 Redshift 表
问题描述
这是尝试删除在过去 2 个月内未访问的表的存储过程。
Information_schema.tables 包含我们的 redshift 集群中存在的所有表。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]
-----------------------------------------------;
谁能帮我解决这个问题?非常感谢任何反馈!
解决方案
我认为您不需要在 LIKE 标准中使用 quote_literal 函数。
推荐阅读
- python - 向生成的对象添加属性?
- c# - CS1525 C# 无效的表达式术语 ')'
- swiftui - 如何调整 Tabview 图像的大小?(iOS14)
- python - 网页抓取 - 标题
- mule - Anypoint Studio:警告 - 处理 mule 类加载器时出现问题
- json - 回调和 webhook 在同一个文件中
- java - java.lang.NoSuchMethodError: 没有虚拟方法 setTokenProvider(Lcom/google/firebase/internal/InternalTokenProvider;)
- gradle - 自定义 Gradle 任务取决于插件
- wordpress - WordPress 更新和文件的 nginx 权限?
- javascript - 如何修复这部分代码以允许用户从 Firebase Realtime db 获取他们的收藏夹?即使 uid 正常工作,用户也无法查看收藏夹