編集

次の方法で共有


range()

Applies to: ✅ Microsoft FabricAzure Data ExplorerAzure MonitorMicrosoft Sentinel

Generates a dynamic array holding a series of equally spaced values.

Syntax

range(start, stop [, step])

Learn more about syntax conventions.

Parameters

Name Type Required Description
start scalar ✔️ The value of the first element in the resulting array.
stop scalar ✔️ The maximum value of the last element in the resulting array, such that the last value in the series is less than or equal to the stop value.
step scalar The difference between two consecutive elements of the array. The default value for step is 1 for numeric and 1h for timespan or datetime.

Returns

A dynamic array whose values are: start, start + step, ... up to and including stop. The array is truncated if the maximum number of results allowed is reached.

Note

The range function supports a maximum of 1,048,576 (2^20) results.

Examples

The following example returns an array of numbers from one to eight, with an increment of three.

print r = range(1, 8, 3)

Output

r
[1,4,7]

The following example returns an array with all dates from the year 2007.

print r = range(datetime(2007-01-01), datetime(2007-12-31), 1d)

Output

r
["2007-01-01T00:00:00.0000000Z","2007-01-02T00:00:00.0000000Z","2007-01-03T00:00:00.0000000Z",.....,"2007-12-31T00:00:00.0000000Z"]

The following example returns an array with numbers between one and three.

print range(1, 3)

Output

print_0
[1,2,3]

The following example returns a range of hours between one hour and five hours.

print range(1h, 5h)

Output

print_0
1,000,000
["01:00:00","02:00:00","03:00:00","04:00:00","05:00:00"]:

The following example returns a truncated array as the range exceeds the maximum results limit. The example demonstrates that the limit is exceeded by using the mv-expand operator to expand the array into multiple records and then counting the number of records.

print r = range(1,1000000000) 
| mv-expand r 
| count

Output

Count
1,048,576