S
Swetha Shetty

Posted on 24th April 2024|58 views

0
votes

Postgresql Array Functions

What are PostgreSQL array functions?

Answers
P
sri kanth

Posted on 24th April 2024

When the user defines a data type, the corresponding array type created in the background by the PostgreSQL.

We need to remember that each data type has its corresponding array.

Let us consider a few examples:

  • array_append(anyarray, anyelement)

Append an element to the end of an array

For example:

array_append(ARRAY[Sam,Aroni], Tom) 

Result:

{Sam, Aroni, Tom}

  • array_cat(anyarray, anyarray)

concatenate two arrays

For example:

array_cat(ARRAY[1,2,3], ARRAY[4,5])

Result:

{1,2,3,4,5}

  • array_ndims(anyarray)

returns the number of dimensions of the array

For example:

array_ndims(ARRAY[[1,2,3], [4,5,6]])

Result:

2

  • array_length(anyarray, int)

returns the length of the requested array dimension

For example:

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

Result:

3

 

Write your answer

STILL GOT QUERIES?

Get a Live FREE Demo
  • Explore the trending and niche courses and learning maps
  • Learn about tuition fee, payment plans, and scholarships
  • Get access to webinars and self-paced learning videos