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

SVL_UDF_LOG

记录在执行用户定义的函数 (UDF) 期间生成的系统定义的错误和警告消息。

SVL_UDF_LOG 对所有用户可见。超级用户可以查看所有行;普通用户只能查看其自己的数据。有关更多信息,请参阅系统表和视图中的数据可见性

此表中的部分或全部数据也可以在 SYS 监控视图 SYS_UDF_LOG 中找到。SYS 监控视图中的数据经过格式化处理,便于使用和理解。我们建议您使用 SYS 监控视图进行查询。

表列

列名称 数据类型 描述
query bigint 查询 ID。您可以使用此 ID 联接各种其他系统表和视图。
message char(4096) 由函数生成的消息。
created timestamp 日志的创建时间。
traceback char(4096) 此值提供 UDF 的堆栈回溯(如果可用)。有关更多信息,请参阅 Python 标准库中的回溯
funcname character(256) 正在执行的 UDF 的名称。
node integer 生成消息的节点。
slice integer 生成消息的切片。
seq integer 消息在切片上的顺序。

示例查询

以下示例说明 UDF 如何处理系统定义的错误。第一个块显示了返回参数的逆参数的 UDF 函数的定义。在运行函数并提供参数 0 时,如第二个块所示,函数将返回错误。第三个语句将读取在 SVL_UDF_LOG 中记录的错误消息

-- Create a function to find the inverse of a number CREATE OR REPLACE FUNCTION f_udf_inv(a int) RETURNS float IMMUTABLE AS $$ return 1/a $$ LANGUAGE plpythonu; -- Run the function with a 0 argument to create an error Select f_udf_inv(0) from sales; -- Query SVL_UDF_LOG to view the message Select query, created, message::varchar from svl_udf_log; query | created | message -------+----------------------------+--------------------------------------------------------- 2211 | 2015-08-22 00:11:12.04819 | ZeroDivisionError: long division or modulo by zero\nNone

以下示例将日志记录和警告消息添加到 UDF 中,以便被零除运算生成警告消息而不是停止并显示错误消息。

-- Create a function to find the inverse of a number and log a warning CREATE OR REPLACE FUNCTION f_udf_inv_log(a int) RETURNS float IMMUTABLE AS $$ import logging logger = logging.getLogger() #get root logger if a==0: logger.warning('You attempted to divide by zero.\nReturning zero instead of error.\n') return 0 else: return 1/a $$ LANGUAGE plpythonu;

以下示例运行该函数,然后查询 SVL_UDF_LOG 以查看消息。

-- Run the function with a 0 argument to trigger the warning Select f_udf_inv_log(0) from sales; -- Query SVL_UDF_LOG to view the message Select query, created, message::varchar from svl_udf_log; query | created | message ------+----------------------------+---------------------------------- 0 | 2015-08-22 00:11:12.04819 | You attempted to divide by zero. Returning zero instead of error.