Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f5chS-0004mf-4g for pgsql-general@arkaria.postgresql.org; Mon, 09 Apr 2018 19:43:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f5chQ-0003i7-O1 for pgsql-general@arkaria.postgresql.org; Mon, 09 Apr 2018 19:43:32 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f5chP-0003hu-6P for pgsql-general@lists.postgresql.org; Mon, 09 Apr 2018 19:43:32 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f5cgp-00053p-Tg for pgsql-general@lists.postgresql.org; Mon, 09 Apr 2018 19:42:59 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 59E4421924; Mon, 9 Apr 2018 15:42:54 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Mon, 09 Apr 2018 15:42:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; bh=tJn+ziZSBWA7mkkKA2LImldIeG/DI DaCxE5tHYYTTq4=; b=ErLEYl5/188e3xiIIQJPiZW1jdkNrY4nd1qMPevnJi1XX nUc8uqZbWTFM9/COKhqBsUHTSyTqvUi/PXlTpUAS+3zoXSV2ln4IcFZu1nG1WlXL +3LQjPoGRs52Mz3HIeRJ5St9YcHS8nNdHfSC5Bo05o+LiBLalw2Kf3KkDoRGyU+O 6N9Xc32+ZItpohSBV9EoNgOVc/Dpe0Fx8kr6eK7lCYN2jYOZvIiar1x7STcQ6waK /rAu0dsYtfGfnbqLDSv4Y5icFZ5WMtIXNsE1UzGioi2Ar2rJzs/By63TipKZ6BI3 Ug/mYFRdEvH5/ZgEmDEugW9wudE+Hw5cwqBsHpkHA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=tJn+zi ZSBWA7mkkKA2LImldIeG/DIDaCxE5tHYYTTq4=; b=BvBqqtOnJfZndctIr1l2/s zF+FFsF7s+pYS9NbZKt2MhNPSlK8yhgWs2GxgdYx/07/4AaDjxoMXrElMWe3qsOS ldiaW0HYG+egCfB0Nokffh/NgBC5/ixMGTy5cI8FpxpRmEccjggHeDFAwJSXiK/f /xoiCdVOsTXRD6DPqMiFuyQOm1QbiEgmq7PXfSdjmfa8z9SWyUkFOEJw04MovjSq lQ+dA+hE8rVklCUlkvyr4HIojOXl8jsy5hNMHcpi1JMoGVAvH2JeKeGWwzEeUkH+ gomVe3Ip2oiuGThHJTrqmNpSd8Hw6LkfkgKmIvuB6l7Iv47JGEwgc/7JM3/5+Dtw == X-ME-Sender: Received: from [192.168.1.2] (71-35-123-124.tukw.qwest.net [71.35.123.124]) by mail.messagingengine.com (Postfix) with ESMTPA id 8D9E510253; Mon, 9 Apr 2018 15:42:53 -0400 (EDT) Subject: Re: Conflict between JSON_AGG and COPY To: =?UTF-8?B?xJDhu5cgTmfhu41jIFRyw60gQ8aw4budbmc=?= Cc: pgsql-general References: <152647427.13167958.1523097853639.JavaMail.zimbra@digi-texx.vn> <688939859.13457181.1523245447673.JavaMail.zimbra@digi-texx.vn> From: Adrian Klaver Message-ID: <95acfff8-8e72-0d08-fd89-294fcca8dc49@aklaver.com> Date: Mon, 9 Apr 2018 12:42:52 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <688939859.13457181.1523245447673.JavaMail.zimbra@digi-texx.vn> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 04/08/2018 08:44 PM, Đỗ Ngọc Trí Cường wrote: > Dear Arian Klaver, > > I think there is a misunderstood here. > > I think that I quite understand how is the second query run. > > The question I asked here is why exporting data, which is generated by a > query "JSON_AGG" , with command "COPY". The data contain "\n" as 2 > characters instead of "new line" character. > > 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. COPY (select json_build_object('RECORDS', ARRAY_AGG(t) ) from test_table t) TO '/home/postgres/test2.json'; cat test2.json {"RECORDS" : [{"id":1,"username":"john","fullname":"John"},{"id":2,"username":"anna","fullname":"Anna"},{"id":3,"username":"sussi","fullname":"Sussi"},{"id":4,"username":"david","fullname":"David Beckham"},{"id":5,"username":"wayne","fullname":"Wayne Rooney"}]} > > Thank you and best regards, > > > Đỗ Ngọc Trí*Cường*(Mr.) | *Software Development Department*| +84 28 3715 > 5325 -- Adrian Klaver adrian.klaver@aklaver.com