w3resource

PostgreSQL ARRAY_REMOVE() function

ARRAY_REMOVE() function

The ARRAY_REMOVE() function in PostgreSQL is used to eliminate all elements equal to a specified value from a one-dimensional array. This function is particularly useful for cleaning up arrays by removing unwanted or duplicate elements.

Uses of the PostgreSQL ARRAY_REMOVE() Function
  • Clean Up Arrays: Remove specific unwanted values from an array.

  • Eliminate Duplicates: Ensure no repeated elements by removing duplicates.

  • Dynamic Array Modification: Adjust arrays by removing certain elements dynamically.

  • Data Filtering: Filter out undesired data points from an array.

Syntax:

array_remove(anyarray, anyelement)

Return Type:

anyarray

PostgreSQL Version: 9.3

Example: PostgreSQL ARRAY_REMOVE() function

Code:

SELECT array_remove(ARRAY[1,2,3,2], 2);

Sample Output:

 array_remove
--------------
 {1,3}
(1 row)

Previous: ARRAY_PREPEND function
Next: ARRAY_REPLACE 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://w3resource.com/PostgreSQL/postgresql_array_remove-function.php