프로그램 사용/postgreSQL

postgresql 에서 ,로 구분되는 문자열로 내보내기

구차니 2019. 12. 18. 10:42

말이 어렵다 -ㅁ-

array_agg()를 통해서 합치게 되면

{1,2,3} 이런식으로 중괄호가 붙게 되는데

이걸 없애고 순수하게(?)

1,2,3 으로만 출력하게 하는 방법

 

아래와 같이 하면 array_agg에 의해 배열로 {}로 붙게 되고 array_to_string()에 의해

{}가 제거된 채 원하는 의도대로 1,2,3 으로 출력되게 된다.

array_to_string(array_agg(DISTINCT datas),',')

[링크 : https://stackoverflow.com/questions/11899024/postgresql-query-to-return-results-as-a-comma-separated-list]