PG_LAST_COPY_ID - Amazon Redshift
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

PG_LAST_COPY_ID

返回当前会话中最近完成的 COPY 命令的查询 ID。如果当前会话中尚未运行任何 COPY 命令,PG_LAST_COPY_ID 将返回 -1。

当 COPY 命令开始加载过程时,将更新 PG_LAST_COPY_ID 的值。如果 COPY 因加载数据无效而失败,则会更新 COPY ID,因此您可在查询 STL_LOAD_ERRORS 表时使用 PG_LAST_COPY_ID。如果回滚了 COPY 事务,则不会更新 COPY ID。

如果 COPY 命令因加载过程开始前出现的错误(如语法错误、访问错误、凭证无效或权限不足)而失败,则不会更新 COPY ID。如果 COPY 在分析压缩步骤(在成功连接之后、数据加载之前开始)中失败,则将不会更新 COPY ID。

语法

pg_last_copy_id()

返回类型

返回整数。

示例

以下查询返回当前会话中的最新 COPY 命令的查询 ID。

select pg_last_copy_id(); pg_last_copy_id --------------- 5437 (1 row)

以下查询将 STL_LOAD_ERRORS 联接到 STL_LOADERROR_DETAIL 以查看当前会话中的最近一次加载过程中发生的错误的详细信息:

select d.query, substring(d.filename,14,20), d.line_number as line, substring(d.value,1,16) as value, substring(le.err_reason,1,48) as err_reason from stl_loaderror_detail d, stl_load_errors le where d.query = le.query and d.query = pg_last_copy_id(); query | substring | line | value | err_reason -------+-------------------+------+----------+------------------------------------------------- 558| allusers_pipe.txt | 251 | 251 | String contains invalid or unsupported UTF8 code 558| allusers_pipe.txt | 251 | ZRU29FGR | String contains invalid or unsupported UTF8 code 558| allusers_pipe.txt | 251 | Kaitlin | String contains invalid or unsupported UTF8 code 558| allusers_pipe.txt | 251 | Walter | String contains invalid or unsupported UTF8 code