postgresql 함수 stringagg、array_agg

string_agg、array_agg 의 역할 과 효과 가 많 지 않 습 니 다. 변환 후 결과 의 데이터 형식 이 일치 하지 않 을 뿐 입 니 다.
string_agg 함수
with tmp_t0 as (
    select 'A'::varchar as c1 union all
    select 'B'::varchar as c1 union all
    select 'C'::varchar as c1 
)
select string_agg(c1,',') 
  from tmp_t0
  ; 

 string_agg 
------------
 A,B,C
(1 row)

array_agg 함수
with tmp_t0 as (
    select 'A'::varchar as c1 union all
    select 'B'::varchar as c1 union all
    select 'C'::varchar as c1 
)
select array_agg(c1) 
  from tmp_t0
  ; 

 array_agg 
-----------
 {A,B,C}
(1 row)

참고:https://www.postgresql.org/docs/9.6/static/functions-aggregate.html https://www.postgresql.org/docs/9.6/static/functions-string.html

좋은 웹페이지 즐겨찾기