w3resource

PostgreSQL ARRAY_FILL() function

ARRAY_FILL() function

The ARRAY_FILL() function in PostgreSQL creates an array initialized with a specified value and dimensions. This function allows for the creation of arrays with consistent values and can optionally set lower bounds other than 1.

Uses of the PostgreSQL ARRAY_FILL() Function
  • Initialize Arrays: Create arrays with predetermined values for all elements.

  • Specify Dimensions: Generate arrays with specific dimensions and sizes.

  • Set Custom Bounds: Define arrays with custom lower bounds for indices.

  • Uniform Data: Ensure uniformity in array elements for testing or default settings.

Syntax:

array_fill(anyelement, int[], [, int[]])

Return Type:

anyarray

PostgreSQL Version: 9.3

Example: PostgreSQL ARRAY_FILL() function

Code:

SELECT array_fill(7, ARRAY[3], ARRAY[2]);

Sample Output:

  array_fill
---------------
 [2:4]={7,7,7}
(1 row)

Previous: ARRAY_DIMS function
Next: ARRAY_LENGTH function



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/PostgreSQL/postgresql_array_fill-function.php