.. _intarray:

=========
intarray
=========


插件intarray简介
----------------------

intarray模块为操作整数的null-free数组提供一些有用的函数和操作符。也支持使用其中的一些操作符执行索引搜索。
如果提供的数组包含任何空元素，那么所有这些操作符都将抛出一个错误。
这些操作符中的一些只对一维数组敏感。尽管他们将接受多个维数的输入数组，数组将按照存储的顺序当做一维数组。

- 插件名为intarray

- 插件版本 V1.0


插件intarray加载方式
----------------------

使用时需要create extension intarray。

示例:

.. code::

	create extension intarray;


插件intarray参数配置
-------------------------

无需配置任何参数。


插件intarray使用方法
-------------------------

icount
^^^^^^^^

计算数组中元素的个数

**语法**

	icount(_int4) RETURNS int;

**示例**

.. code::

	TEST=# select icount('{1,2,3}'::int[]);
	 icount
	--------
		  3
	(1 行记录)

sort
^^^^^^

对int数组进行排序。

**语法**

	sort(int[]) returns int[];
	sort(int[], text dir) returns int[];

**参数**

	dir
		如果dir是asc，则对数组进行升序排序。如果dir是desc，则对数组进行降序排序。

**示例**

.. code::

	TEST=# select sort('{2,1,5,7,3}');
		sort
	-------------
	 {1,2,3,5,7}
	(1 行记录)

	TEST=# select sort('{2,1,5,7,3}', 'asc');
		sort
	-------------
	 {1,2,3,5,7}
	(1 行记录)

	TEST=# select sort('{2,1,5,7,3}', 'desc');
		sort
	-------------
	 {7,5,3,2,1}
	(1 行记录)

sort_asc
^^^^^^^^^^

以升序的方式对数组进行排序。

**语法**

	sort_asc(int[]) returns int[];

**示例**

.. code::

	TEST=# select sort_asc('{2,1,5,7,3}');
	  sort_asc
	-------------
	 {1,2,3,5,7}
	(1 行记录)


sort_desc
^^^^^^^^^^^

以降序的方式对int数组进行排序。

**语法**

	sort_desc(int[]) returns int[];

**示例**

.. code::

	TEST=# select sort_desc('{2,1,5,7,3}');
	  sort_desc
	-------------
	 {7,5,3,2,1}
	(1 行记录)

uniq
^^^^^

消除相邻的相同的元素。

**语法**

	uniq(int[]) returns int[];

**示例**

.. code::

	TEST=# select uniq('{2,1,5,7,7,7,3}');
		uniq
	-------------
	 {2,1,5,7,3}
	(1 行记录)

idx
^^^^^

匹配item的第一个元素中的索引（如果没有则为0）。

**语法**

	idx(int[], int item) returns int;

**参数**

	item
		需要匹配的值。

**示例**

.. code::

	TEST=# select idx(array[1,23,5,2,5,2], 2);
	 idx
	-----
	   4
	(1 行记录)



subarray
^^^^^^^^^

在start位置开始的，len个元素的数组的一部分。

**语法**

	subarray(int[], int start) returns int[];
	subarray(int[], int start, int len) returns int[];

**参数**

	start
		开始的位置。
	len
		指定子数组的长度。
	
**示例**

.. code::

	TEST=# select subarray('{1,2,3,2,1}'::int[], 2, 3);
	 subarray
	----------
	 {2,3,2}
	(1 行记录)


intset
^^^^^^^^

制作单个元素的数组。

**语法**

	intset(int) returns int[];

**示例**

.. code::

	TEST=# select intset(42);
	 intset
	--------
	 {42}
	(1 行记录)


intarray模块中支持的操作符
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

&&  @>  @<  #  +  -  |  &  @@


插件intarray卸载方法
---------------------

不需要intarray插件只需要卸载插件即可。

**示例**

.. code::

	drop extension intarray;


插件intarray升级方法
-------------------------

intarray扩展插件通常随KingbaseES安装包一并升级。通常情况下用户无法单独升级插件。
