Query syntax
WITH ORDINALITY clause
The WITH ORDINALITY
clause can be used with set functions in the FROM
clause of a query.
An additional integer column will be added to the table, which numbers the rows returned by the function, starting from 1. By default, the generated column is named ordinality
.
See Set-returning functions for a list of supported set functions.
Here is a simple example of how the WITH ORDINALITY
clause works.
The output will be as follows.
If we have a table t
like so:
We can use the unnest
function on the column arr
, call WITH ORDINALITY
, and rename the newly generated columns.
The results will be as follows.
Was this page helpful?