array 안에서는 select 문을 통해 다른 값들을 받아 하나의 필드로 출력을 해준다.
개꿀! (unnest로 풀면되지!)
The result I get is:
+-----------------------+
| ?column? |
+-----------------------+
| 15:00:00 Dissertation |
| 17:00:00 Dinner |
| 23:00:00 Sleep |
+-----------------------+
Now that I have my rows, I can turn them into an array. Now, the ARRAY function needs to be invoked via a SELECT. Thus, using ARRAY means that we’re using a subselect. The inner SELECT is what we did above. The outer one is just our call to ARRAY:
SELECT ARRAY(SELECT meeting_at::time || ' ' || description
FROM Appointments
WHERE meeting_at::date = '2014-may-23'
ORDER BY meeting_at);
And sure enough, we get a one-row, one-column result:
+--------------------------------------------------------------+
| array |
+--------------------------------------------------------------+
| {"15:00:00 Dissertation","17:00:00 Dinner","23:00:00 Sleep"} |
+--------------------------------------------------------------+
[링크 : https://lerner.co.il/2014/05/23/turning-postgresql-rows-arrays-array/]
'프로그램 사용 > postgreSQL' 카테고리의 다른 글
postgresql 데이터베이스 다른 이름으로 복구하기 (0) | 2019.10.07 |
---|---|
postgresql rank() over() (0) | 2019.10.04 |
postgresql LEFT JOIN = LEFT OUTER JOIN (0) | 2019.10.01 |
다른 테이블과 join 하여 update 하기 (0) | 2019.10.01 |
where 조건에 다른 select문 사용하기 - exists (0) | 2019.09.30 |