array() function
The array() function creates an array of a specified type.
Syntax
The array() function has the following
syntax:
array = array(int type);
The
type value is an integer
code that specifies the type of
array to create, as shown in the following table:
| Code | Type | Description |
|---|---|---|
| 1 | int1 | 8 bit. |
| 2 | int2 | 16 bit. |
| 3 | int4 | 32 bit. |
| 4 | int8 | 64 bit. |
| 5 | date | Date range of January 1, 0001 - December 31, 9999. The disk usage is 4 bytes. |
| 6 | time | Hours, minutes, and seconds to six decimal positions. The range is 00:00:00.000000 - 23:59:59.999999. The disk usage is 8 bytes. |
| 7 | timestamp | Date part and time part, with seconds stored to 6 decimal positions. The range is January 1, 0001 00:00:00.000000 - December 31, 9999 23:59:59.999999. The disk usage is 8 bytes. |
| 8 | varchar | Variable length, with a maximum length of 64,000 characters. There is no blank padding; data is stored as entered. For varchar strings of length n, the disk usage is no more than n + 2 bytes. |
| 9 | nvarchar | Variable-length Unicode data with a maximum length of 16,000 characters. Using UTF-8 encoding, each Unicode code point requires 1 - 4 bytes of storage. Therefore, a 10-character string requires 10 bytes of storage if it is ASCII, up to 20 bytes if it is Latin, or as many as 40 bytes if it is pure Kanji (but typically 30 bytes). |
| 10 | float | Floating-point number with precision 1 - 15. A precision less than 6 uses 4 bytes. A precision of 7 - 15 uses 8 bytes. |
| 11 | double | Value equivalent to float with precision 15, using 8 bytes. |
| 15 | timetz | Hours, minutes, seconds to 6 decimal positions, and time zone offset from GMT. |
Returns
The function creates the specified type of array.Example
Consider the following example:
create table array_t(col1 int,col2 varchar(100));
CREATE TABLE
The following INSERT query creates an array of type int2 and stores it in the
table:
insert into array_t values(1,array(2));
INSERT 0 1
The following query shows that an array was created and stored
in the array_t
table:
select * from array_t;
col1 | col2
------+------
1 | ARR
(1 row)