postgres=# select * from unnest(ARRAY[1,2,3]) with ordinality;
unnest | ordinality
--------+------------
1 | 1
2 | 2
3 | 3
postgres=# select unnest(ARRAY[1,2,3]) with ordinality;
ERROR: syntax error at or near "ordinality"
LINE 1: select unnest(ARRAY[1,2,3]) with ordinality;
though this works
postgres=# select unnest(ARRAY[1,2,3]);
unnest
--------
1
2
3
The manual
http://www.postgresql.org/docs/devel/static/queries-table-expressions.html#QUERIES-TABLEFUNCTIONS
says
"Columns returned by table functions can be included in SELECT, JOIN,
or WHERE clauses in the same manner as columns of a table, view, or
subquery."
There is no qualification of that for WITH ORDINALITY, nor an example
So either the manual is wrong, or the syntax is.
Also, WITH ORDINALITY is not mentioned here...
http://www.postgresql.org/docs/devel/static/functions-array.html
--
Simon Riggs http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services