seq()

Returns a sequentially incrementing number starting from 1 on each call.

Syntax

seq()

Description

The seq() function takes no arguments and returns a 64-bit integer that increments by 1 each time a row is processed during query execution. The counter starts at 1 at the beginning of query execution.

Sequential number assignment is handled as an atomic operation, ensuring unique numbers are assigned without duplicates even in parallel execution environments.

Error codes

N/A

Usage examples

To prepare the WEB_APACHE_SAMPLE table used in these examples, refer to Preparing sample data.

  1. Assign a sequential number to each access log entry.

    table limit=5 WEB_APACHE_SAMPLE | eval n = seq()
    | fields n, _time, src_ip, uri, status
    

Compatibility

The seq() function is available since before Sonar 4.0.