RefLib

Reference library for AI

Back

postgresql_16:3.1.2.3 Subscripts

PostgreSQL 16 > The SQL Language > SQL Syntax > Value Expressions > Subscripts

If an expression yields a value of an array type, then a specific element of the array value can be extracted by writing *expression*[*subscript*] or multiple adjacent elements (an “array slice”) can be extracted by writing *expression*[*lower_subscript*:*upper_subscript*] (Here, the brackets [ ] are meant to appear literally.) Each *subscript* is itself an expression, which will be rounded to the nearest integer value.

In general the array *expression* must be parenthesized, but the parentheses can be omitted when the expression to be subscripted is just a column reference or positional parameter. Also, multiple subscripts can be concatenated when the original array is multidimensional. For example: mytable.arraycolumn[4] mytable.two_d_column[17][34] $1[10:42] (arrayfunction(a,b))[42] The parentheses in the last example are required. See (see postgresql_16:3.5.15) for more about arrays.

Back