9.2 부터는 JSON 을 내부적으로 지원합니다.
이런게 오픈소스의 매력이죠.
scott@[local]:5432:scottdb]
SQL> select * from dept;
10 | ACCOUNTING | NEW YORK
20 | RESEARCH | DALLAS
30 | SALES | CHICAGO
40 | OPERATIONS | BOSTON
scott@[local]:5432:scottdb]
SQL> select array_agg(d) from dept d;
{"(10,ACCOUNTING,\"NEW YORK\")","(20,RESEARCH,DALLAS)","(30,SALES,CHICAGO)","(40,OPERATIONS,BOSTON)"}
scott@[local]:5432:scottdb]
SQL> select array_to_json(array_agg(d)) from dept d;
[{"deptno":10,"dname":"ACCOUNTING","loc":"NEW YORK"},{"deptno":20,"dname":"RESEARCH","loc":"DALLAS"},{"deptno":30,"dname":"SALES","loc":"CHICAGO"},{"deptno":40,"dname":"OPERATIONS","loc":"BOSTON"}]
scott@[local]:5432:scottdb]
SQL>
누워서 떡먹기네요. 근데, 누워서 먹으면 체하겠죠^^