Here is a synopsis of the steps you take to debug scalar, aggregate, and table functions using trace tables.
- Create a trace table using the CREATE GLOBAL TEMPORARY TRACE TABLE statement.
The first two columns of the trace table are used by the Teradata function trace subsystem. Any columns that are defined beyond the first two are available for a UDF to use to write trace output during execution.
- Enable the trace table for function trace output using the SET SESSION FUNCTION TRACE statement.
You can specify an optional function trace string that the UDF can obtain during execution.
- Invoke the function.
- Call FNC_Trace_String in the UDF to get the function trace string that was specified in the SET SESSION FUNCTION TRACE statement.
You can use the value of the trace string to determine what to output to the trace table.
- Call FNC_Trace_Write_DL to write trace output to the columns of a trace table.
If you are debugging an aggregate or table function, you can optionally call FNC_Trace_Write, which is restricted to UDFs that execute on an AMP.
- Use a SELECT statement to query the trace table and retrieve the trace output from the UDF.