Database Reference
In-Depth Information
Intarray
This extension provides a set of functions and operators for working with integer arrays. It
also provides support for indexed search using operators. The operations provided by this
extension are used for one-dimensional arrays.
In this example, you will create a table of contents and add a disordered array. Then you
will use two functions, the first to sort the array and the second to display the number of
elements.
To start, you will install the intarray extension, create the table contents, and insert a re-
cord:
$ heroku pg:psql --app your-app-name
CREATE EXTENSION intarray;
CREATE TABLE contents (elements INT[]);
INSERT INTO contents (elements) VALUES (ARRAY[2, 4, 3, 1]);
Next, you will sort the array of elements:
SELECT sort_asc(elements) FROM contents;
sort_asc
-----------
{1,2,3,4}
Finally, you will discover the number of elements in the array.
SELECT icount(elements) FROM contents;
icount
--------
4
For other useful functions, check the documentation at http://www.postgresql.org/docs/cur-
rent/static/intarray.html .
Search WWH ::




Custom Search