Called by an external stored procedure, UDM, or UDF to write trace output into a temporary trace table defined by a CREATE GLOBAL TEMPORARY TRACE TABLE statement.
Syntax
void FNC_Trace_Write_DL ( int argc, void *argv[], int length[] )
Syntax Elements
- argc
- the count of output arguments in the argv array.
This value should match the number of columns in the trace table beyond the first two mandatory columns that are used by the Teradata function trace subsystem.
- argv
- an array of pointers to data to write to the columns in a temporary trace table.
- length
- an array of the length, in bytes, of each output argument in the argv array.
The sum of the values of the length elements must be positive and must not exceed the size of a row in the trace table.
Array Element Column argv[0] Debug_Trace.Sum_X argv[1] Debug_Trace.Sum_Y argv[2] Debug_Trace.Trace_Text
Usage Notes
Trace output values are not validated. For example, stored values are incorrect when numeric values are too big for the receiving column or when character strings contain characters that are not valid.
If you store incorrect values, you might not be able to select data from the trace table. For example, if you write an invalid date to a TIMESTAMP column, a subsequent select on that data returns an invalid date error and no result. To read the bad TIMESTAMP data from the trace table and determine what is wrong, take the following steps:
- Write another UDF that defines its input argument as a TIMESTAMP and converts it to a string result.
- Use that UDF in the SELECT statement to read the TIMESTAMP data from the trace table to see what is wrong with it.
To avoid storing incorrect values that you might not be able to select, create the trace table with only character columns (beyond the first two mandatory columns) and format the output data using sprintf. For an example, see Example: Debugging a UDF Using a Trace Table.
If an output string is too long for a corresponding character column, it is truncated without generating an error.
A UDF, UDM, or external stored procedure can call FNC_Trace_Write_DL as often as required.
- No SET SESSION FUNCTION TRACE statement has been submitted to enable a trace table for trace output.
- The sum of the values of the length array elements is negative or exceeds the size of a row in the trace table.
The Teradata function trace subsystem writes values to the first two columns in a trace table. If you try to use the same trace table to simultaneously trace a UDF that runs on an AMP and an external stored procedure, UDM, or UDF that runs on a PE, the sequence number written to the second column will not be sequential. This is because the AMP bases the next sequence number on the sequence of the last row of the trace table and adds one to it no matter where the row originated. The rows inserted into the trace table from the PE are hashed to one AMP based on the PE vproc number and the current sequence number. Therefore if the current sequence number for the PE is 5 and the trace row is added to AMP 1, then a trace write into that table from AMP 1 will have a sequence of 6. The best practice is to avoid simultaneously tracing on an AMP and PE.
Example Using FNC_Trace_Write_DL
INTEGER Sum_x;
INTEGER Sum_y;
CHARACTER_LATIN message[45];
void *argv[3];
int length[3];
...
Sum_x = *In_data_x;
Sum_y = *In_data_y;
argv[0] = &Sum_x;
length[0] = sizeof(INTEGER);
argv[1] = &Sum_y;
length[1] = sizeof(INTEGER);
message = strcpy((char *)message, "The input values");
argv[2] = &message;
length[2] = strlen((const char *)message);
FNC_Trace_Write_DL(3, argv, length);
Related Information
For more information on CREATE GLOBAL TEMPORARY TRACE TABLE, see Teradata Vantageā¢ - SQL Data Definition Language Syntax and Examples, B035-1144.