I am trying to understand the second argument to the PostgreSQL generate_subscripts
function. The documentation states that the second argument is the size of the array over which indexes should be generated:
generate_subscripts is a convenience function that generates a set of valid indexes for a given dimension of a given array.
However, for my two-dimensional array of examples, providing arguments 1
or 2
, the same output is generated.
WITH data AS ( select (array[['1','spam','3'], ['4','eggs','6'], ['7','ham','9']]) AS arr ) SELECT arr[i][2] AS food FROM data, generate_subscripts((SELECT arr FROM data), 1) i;
and
WITH data AS ( select (array[['1','spam','3'], ['4','eggs','6'], ['7','ham','9']]) AS arr ) SELECT arr[i][2] AS food FROM data, generate_subscripts((SELECT arr FROM data), 2) i;
(Note 1
vs. 2
) generate the same output:
food ------ spam eggs ham (3 rows)
I am afraid that I do not understand the second argument to generate_subscripts
. Can anyone with much experience figure out what this argument does?
I am running PostgreSQL 9.1.6.