On 04/08/2018 08:44 PM, Đỗ Ngọc Trí Cường wrote:
Presently, COPY TO will never emit an octal or hex-digits backslash sequence, but it does use the other sequences listed above for those control characters.
The second query is for the old version of PostgreSQL (9.3 and previous) cause of they don't have JSON_AGG aggregate function. Since 9.4, we have "JSON_AGG" already. So I want to rewrite and reduce the length of the query. But it is don't work as I expected with command COPY.
Actually, COPY FROM will interpret the newlines just fine. The issue here is that most other programs that injects csv are not as intelligent and will look at the \n as content as opposed to a control character. Those programs will, however, recognize an actual newline within the quoted field as being valid data: but it doesn't appear that COPY is capable outputting such.
David J.