Contents
generate_subscripts()
A function generating the subscripts for an array
generate_subscripts()
is a system function generating a series of integers representing the subscripts of the specified array.
generate_subscripts()
was added in PostgreSQL 8.4.
Usage
generate_subscripts (array
anyarray
,dim
integer
) → setofinteger
generate_subscripts (array
anyarray
,dim
integer
,reverse
boolean
) → setofinteger
Change history
- PostgreSQL 8.4
- added (commit 1fcb977a)
Examples
Basic usage example for generate_subscripts()
:
postgres=# SELECT generate_subscripts(ARRAY['foo','bar','baz'], 1); generate_subscripts --------------------- 1 2 3 (3 rows)
Subscripts can be returned in reverse order:
postgres=# SELECT generate_subscripts(ARRAY['foo','bar','baz'], 1, TRUE); generate_subscripts --------------------- 3 2 1 (3 rows)
Generating subscripts for a multi-dimensional array:
postgres=# SELECT generate_subscripts(ARRAY[['foo','bar','baz'],['boo','bom','bop']], 1); generate_subscripts --------------------- 1 2 (2 rows)
No values are returned if an invalid array dimension is specified:
postgres=# SELECT generate_subscripts(ARRAY['foo','bar','baz'], 2); generate_subscripts --------------------- (0 rows)
References
- PostgreSQL documentation: Subscript Generating Functions