SVL_UDF_LOG - Amazon Redshift

SVL_UDF_LOG

Records system-defined error and warning messages generating during user-defined function (UDF) execution.

SVL_UDF_LOG is visible to all users. Superusers can see all rows; regular users can see only their own data. For more information, see Visibility of data in system tables and views.

Some or all of the data in this table can also be found in the SYS monitoring view SYS_UDF_LOG. The data in the SYS monitoring view is formatted to be easier to use and understand. We recommend that you use the SYS monitoring view for your queries.

Table columns

Column name Data type Description
query bigint The query ID. You can use this ID to join various other system tables and views.
message char(4096) The message generated by the function.
created timestamp The time that the log was created.
traceback char(4096) If available, this value provides a stack traceback for the UDF. For more information, see traceback in the Python Standard Library.
funcname character(256) The name of the UDF that is executing.
node integer The node where the message was generated.
slice integer The slice where the message was generated.
seq integer The sequence of the message on the slice.

Sample queries

The following example shows how UDFs handle system-defined errors. The first block shows the definition for a UDF function that returns the inverse of an argument. When you run the function and provide a 0 argument, as the second block shows, the function returns an error. The third statement reads the error message that is logged in 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

The following example adds logging and a warning message to the UDF so that a divide by zero operation results in a warning message instead of stopping with an error message.

-- 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;

The following example runs the function, then queries SVL_UDF_LOG to view the message.

-- 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.