8.10.4. Modifying an ARRAY can be completely replaced by limit {25000,25000, 27000,27000} WHEREnameCarol; or using ARRAY expression syntax: limit [25000,25000, 27000,27000] WHEREnameCa
8.10.4. UPDATE sal_emp SET pay_by_quarter = '{25000,25000, 27000,27000}' WHERE name = 'carol '; or use the ARRAY expression syntax: UPDATE sal_emp SET pay_by_quarter = ARRAY [25000,25000, 27000,27000] WHERE name = 'Ca
8.10.4. Modify an array
An array value can be completely replaced:
UPDATE sal_emp SET pay_by_quarter = '{25000,25000,27000,27000}' WHERE name = 'Carol';
Or useARRAYExpression syntax:
UPDATE sal_emp SET pay_by_quarter = ARRAY[25000,25000,27000,27000] WHERE name = 'Carol';
Or update an element:
UPDATE sal_emp SET pay_by_quarter[4] = 15000 WHERE name = 'Bill';
Or update a piece:
UPDATE sal_emp SET pay_by_quarter[1:2] = '{27000,27000}' WHERE name = 'Carol';
You can assign a value to an existing element that is adjacent to an existing element, or assign a value to an existing area that is adjacent to or overlapped with the existing data to expand an array. For example, if an arrayMyarrayCurrently, there are four elements.Myarray [5]After a value is assigned, it has five elements. Currently, this expansion only allows multi-dimensional arrays and does not allow operations on multi-dimensional arrays.
Array fragment assignment allows you to create arrays that do not use a base value. For example, we canArray [-2: 7]Assign a value to create an array with the script value between-2 and 7.
The new array value can also be connected using the concatenation operator.|Structure.
SELECT ARRAY[1,2] || ARRAY[3,4]; ?column?----------- {1,2,3,4}(1 row)SELECT ARRAY[5,6] || ARRAY[[1,2],[3,4]]; ?column?--------------------- {{5,6},{1,2},{3,4}}(1 row)
The join operator allows an element to be pushed to the beginning or end of a one-dimensional array. It also accepts twoNAn array of dimensions, or an arrayNPeacekeepingN + 1Dimension Array.
After an element is pushed to the beginning of a one-dimensional array, the result is an array where its low-bound subscript equals to the low-bound subscript of the right-hand operand minus one, if an element is pushed to the end of a one-dimensional array, the result array is an array that keeps the left-hand side operand low. For example:
SELECT array_dims(1 || ARRAY[2,3]); array_dims------------ [0:2](1 row)SELECT array_dims(ARRAY[1,2] || 3); array_dims------------ [1:3](1 row)
If two arrays with the same dimension are connected together, the lower subscript of the outer dimension of the left-hand side operand is maintained. The result is an array that contains each element of the left-hand side operand followed by each element of the right-hand side operand. For example:
SELECT array_dims(ARRAY[1,2] || ARRAY[3,4,5]); array_dims------------ [1:5](1 row)SELECT array_dims(ARRAY[[1,2],[3,4]] || ARRAY[[5,6],[7,8],[9,0]]); array_dims------------ [1:5][1:2](1 row)
IfNDimension Array toN + 1The start or end of a dimension array. The result is similar to that of the preceding array element. EachNThe sub-arrays of dimensions are actuallyN + 1The outer dimension of the dimension array. For example:
SELECT array_dims(ARRAY[1,2] || ARRAY[[3,4],[5,6]]); array_dims------------ [0:2][1:2](1 row)
Functions can also be used for arrays.Array_prepend, AndArray_append, AndArray_catStructure. The first two parameters support only one-dimensional arrays, whileArray_catMulti-dimensional arrays are supported. Note that using the join operators discussed above is better than using these functions directly. In fact, these functions are mainly used to implement join operators. However, it may be necessary to use them directly in user-defined creation functions. Some examples:
SELECT array_prepend(1, ARRAY[2,3]); array_prepend--------------- {1,2,3}(1 row)SELECT array_append(ARRAY[1,2], 3); array_append-------------- {1,2,3}(1 row)SELECT array_cat(ARRAY[1,2], ARRAY[3,4]); array_cat----------- {1,2,3,4}(1 row)SELECT array_cat(ARRAY[[1,2],[3,4]], ARRAY[5,6]); array_cat--------------------- {{1,2},{3,4},{5,6}}(1 row)SELECT array_cat(ARRAY[5,6], ARRAY[[1,2],[3,4]]); array_cat--------------------- {{5,6},{1,2},{3,4}}