TSL_Flush function

The TSL_Flush function flushes data for one or all containers to disk in a single transaction.

Syntax

TSL_Flush(
           handle      lvarchar,
           container   integer DEFAULT NULL,
           writeflag   integer DEFAULT 1)
returns integer 
handle
The table and column name combination that is returned by the TSL_Attach or the TSL_Init function.
container (Optional)
The container identifier. Default is NULL, which indicates all containers.
writeflag (Optional)
An integer that is the sum of flag values that represent whether duplicate elements are allowed for irregular time series and whether logging is reduced. You must supply a value for the duplicate element behavior (1 or 5). Possible values are: 1, 5, 257 (1 + 256), 261 (5 + 256).
1 = Default. Duplicate elements are allowed. Cannot be combined with the value 5.
5 = Duplicate elements replace existing elements. Cannot be combined with the value 1.
256 = Logging is reduced. See the description of the TSOPEN_REDUCED_LOG flag in The flags argument values.

Usage

Use the TSL_Flush function to write time series data to disk as part of a loader program. You must run the TSL_Flush function in a transaction in the context of a loader session that was initialized by the TSL_Init function. You run the TSL_Flush function to save data that is loaded by the TSL_Put, TSL_PutSQL, or TSL_PutRow function.

If you specify that duplicate elements are allowed for irregular time series with the writeflag argument value of 1, the TSL_Flush function inserts data in the same way as the PutElem function. You can specify that duplicate elements replace existing elements that have the same timestamps with the writeflag argument value of 5 so that the TSL_Flush function inserts data in the same way as the PutElemNoDups function.

If you specify reduced logging with the writeflag argument, you must run TSL_Flush function in a transaction that can include only other functions that use reduced logging with the TSOPEN_REDUCED_LOG flag. The elements that are saved are not visible by dirty reads until after the transaction commits.

The TSL_FlushInfo function returns eight categories of information about the last flush operation that saved data to disk.

Returns

An integer that indicates the status of the function:

  • Positive 4-byte number = The top 16 bits represent the number of time series instances that were affected. The lower 16 bits represent the number of elements that were inserted. The returned number of elements that were inserted does not exceed 65535, even if more than 65535 elements were successfully inserted. You can run the TSL_Flush function through the TSL_FlushStatus function to return the number of containers that are affected and the number of elements that are inserted as integers.
  • -1 = Process was interrupted or encountered a severe error.

Example: Run the TSL_Flush function

The following statement saves the data to disk for the table ts_data and the TimeSeries column raw_reads:

BEGIN WORK;
EXECUTE FUNCTION TSL_Flush('ts_data|raw_reads');
COMMIT WORK;

Example: Run the TSL_Flush function with reduced logging

The following statement saves the data to disk with reduced logging:

BEGIN WORK;
EXECUTE FUNCTION TSL_Flush('ts_data|raw_reads', NULL, 257);
COMMIT WORK;

Example: Run the TSL_Flush function with reduced logging and no duplicate elements

The following statement saves the data to disk with reduced logging and replaces existing elements that have the same timestamps as new elements:

BEGIN WORK;
EXECUTE FUNCTION TSL_Flush('ts_data|raw_reads', NULL, 261);
COMMIT WORK;