【问题标题】:Get table name of Redshift COPY commands from stl_load_commits从 stl_load_commits 获取 Redshift COPY 命令的表名
【发布时间】:2020-05-13 02:16:00
【问题描述】:

试图获取在特定日期运行的 COPY 命令列表以及为每个 COPY 命令更新的表。

使用此查询:

select
        slc.query as query_id, 
        trim(slc.filename) as file, 
        slc.curtime as updated, 
        slc.lines_scanned as rows, 
        sq.querytxt as querytxt
from stl_load_commits slc
    join stl_query sq on sq.query = slc.query
where trunc(slc.curtime) = '2020-05-07';

我们如何获取每个 COPY 命令更新的表?也许在querytxt 上使用 Redshift RegEx 函数?或者加入另一个系统表以查找表 ID 或名称?

【问题讨论】:

  • 表名可能是查询中的第二个单词(COPY 之后),因此您可以尝试提取它。查看一些执行复制操作的查询,看看是否可以找到一致的模式。

标签: amazon-redshift


【解决方案1】:

此正则表达式将从stl_query.querytxt 中选择tableschema.table

select
        slc.query as query_id,
        trim(slc.filename) as file,
        slc.curtime as updated,
        slc.lines_scanned as rows,
        sq.querytxt as querytxt,
        REGEXP_REPLACE(LOWER(sq.querytxt), '^copy (analyze )?(\\S+).*$', '$2') AS t
from stl_load_commits slc
    join stl_query sq on sq.query = slc.query
where trunc(updated) = '2020-05-07';

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-01
    • 1970-01-01
    • 2014-03-18
    • 2016-06-10
    • 1970-01-01
    相关资源
    最近更新 更多