选择您的 Cookie 首选项

我们使用必要 Cookie 和类似工具提供我们的网站和服务。我们使用性能 Cookie 收集匿名统计数据,以便我们可以了解客户如何使用我们的网站并进行改进。必要 Cookie 无法停用,但您可以单击“自定义”或“拒绝”来拒绝性能 Cookie。

如果您同意,AWS 和经批准的第三方还将使用 Cookie 提供有用的网站功能、记住您的首选项并显示相关内容,包括相关广告。要接受或拒绝所有非必要 Cookie,请单击“接受”或“拒绝”。要做出更详细的选择,请单击“自定义”。

SVL_UDF_LOG

聚焦模式
SVL_UDF_LOG - Amazon Redshift

记录在执行用户定义的函数 (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.

下一主题:

SVL_USER_INFO

上一主题:

SVL_TERMINATE

本页内容

隐私网站条款Cookie 首选项
© 2025, Amazon Web Services, Inc. 或其附属公司。保留所有权利。