#title 배열
[[TableOfContents]]

==== 테이블 생성 ====
{{{
create table array_test
(
	ref char(5)
,	array_col int[] --> 이렇게 선언한다.
);
}}}

==== 삽입 ====
{{{
insert into array_test values('val01', '{1,2,3,4,5}'); --> {}로 감싸서 입력한다.
insert into array_test values('val01', '{1,2,3,4,5,6,7,8,9}');
}}}

==== 조회 ====
{{{
select * from array_test
}}}
{{{
  ref  |      array_col
-------+---------------------
 val01 | {1,2,3,4,5}
 val02 | {1,2,3,4,5,6,7,8,9}
(2 rows)
}}}
{{{
--배열 요소에 접근하기
select
	array_col[1] as col1 --> 각각의 배열요소에 접근하기 위해서 [n]를 사용한다.
,	array_col[2] as col2	
,	array_col[3] as col3	
,	array_col[4] as col4	
,	array_col[5] as col5	
,	array_col[6] as col6	
,	array_col[7] as col7	
,	array_col[8] as col8	
,	array_col[9] as col9	
from array_test
}}}
{{{
 col1 | col2 | col3 | col4 | col5 | col6 | col7 | col8 | col9
------+------+------+------+------+------+------+------+------
    1 |    2 |    3 |    4 |    5 |      |      |      |
    1 |    2 |    3 |    4 |    5 |    6 |    7 |    8 |    9
(2 rows)
}}}

==== 갱신 ====
{{{
update array_test
set 
	array_col[8] = 8
,	array_col[3] = null
where ref = 'val01';

select 
	array_col 
,	array_col[8] as col8
from array_test
where ref = 'val01';
}}}
{{{
         array_col          | col8
----------------------------+------
 {1,2,NULL,4,5,NULL,NULL,8} |    8
(1 row)
}}}