PostgreSQL trim() Function

The PostgreSQL trim_array() function removes the specified number of elements from the end of the specified array and returns the modified array.

trim_array() Syntax

Here is the syntax of the PostgreSQL trim_array() function:

trim_array(array, number) -> array

Parameters

array

Required. The array to remove elements from.

number

Required. The number of elements to remove.

Return value

The PostgreSQL function trim_array() removes the specified number number of elements from the end of the array and returns the array array.

The trim_array() function will return NULL if the specified array is NULL.

trim_array() Examples

This example shows how to use the PostgreSQL trim_array() function to remove the last 3 elements from the array {1, 2, 3, 4, 5, 6}.

SELECT trim_array(ARRAY[1, 2, 3, 4, 5, 6], 3);
 trim_array
------------
 {1,2,3}