You are viewing documentation about an older version (1.18.0). View latest version

snowflake.snowpark.functions.row_number¶

snowflake.snowpark.functions.row_number() → Column[source]¶

Returns a unique row number for each row within a window partition. The row number starts at 1 and continues up sequentially.

Example:

>>> from snowflake.snowpark.window import Window
>>> df = session.create_dataframe(
...     [
...         [1, 2, 1],
...         [1, 2, 3],
...         [2, 1, 10],
...         [2, 2, 1],
...         [2, 2, 3],
...     ],
...     schema=["x", "y", "z"]
... )
>>> df.select(row_number().over(Window.partition_by(col("X")).order_by(col("Y"))).alias("result")).show()
------------
|"RESULT"  |
------------
|1         |
|2         |
|3         |
|1         |
|2         |
------------
Copy