w3resource

PostgreSQL ARRAY_LENGTH() function

ARRAY_LENGTH() function

The ARRAY_LENGTH() function in PostgreSQL returns the length of a specified dimension in an array. This function is particularly useful for determining the size of arrays, whether single or multi-dimensional.

Uses of the PostgreSQL ARRAY_LENGTH() Function
  • Determine Array Size: Find out the length of an array in a specific dimension.

  • Validate Array Length: Ensure the array meets required size constraints.

  • Dynamic Query Adjustments: Adapt queries based on the length of array dimensions.

  • Analyze Data Structures: Understand the size and structure of arrays for data processing and manipulation.

Syntax:

array_length(anyarray, int)

Return Type :

int

PostgreSQL Version: 9.3

Example: PostgreSQL ARRAY_LENGTH() function

Code:


SELECT array_length(array[1,2,3], 1);

Sample Output:

  array_length
--------------
            3
(1 row)

Previous: ARRAY_FILL function
Next: ARRAY_LOWER function



Follow us on Facebook and Twitter for latest update.