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 1f5XZM-0000Rn-Jf for pgsql-general@arkaria.postgresql.org; Mon, 09 Apr 2018 14:14:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f5XZL-0000E8-HX for pgsql-general@arkaria.postgresql.org; Mon, 09 Apr 2018 14:14:51 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f5XZL-0000Dq-6C for pgsql-general@lists.postgresql.org; Mon, 09 Apr 2018 14:14:51 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f5XZI-0000n4-3b for pgsql-general@lists.postgresql.org; Mon, 09 Apr 2018 14:14:49 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id BA93121165; Mon, 9 Apr 2018 10:14:46 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Mon, 09 Apr 2018 10:14:46 -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=c1qghfQJip0TBZBA6a4D9aQB2Jm4m ibtlbWL+1By+FE=; b=m6AYFbqzDUObqt3OwTZeDLIHbCsYQmi7Zv+UWoYbasjzP reE9qyojXKod4gOJAnESReBLY787HOCBYUUNHJAoZbFlhZ9ztSsPcycys0jtJ+cy 5nwvjcFi8WBeBmhbY6q0ZLq/72wZIlsCm1fCabJQ2sS+IDbkSDeYG9Mzhq+44UkC e9v6/UOd+HIzu/z/HA4pCayIG6AznyE55UyOlTHhcamkVblEV9w1oS0V3oa815o4 USnw93Th5SZL8SP3tRR+bts7qgwSM9WhkYXatFCN0gklHNXrK/zJxssYAWJhYr8H sfO0y2KOkiie20ULWitT3u9ZqgC9mMxReLtZ9/BYg== 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=c1qghf QJip0TBZBA6a4D9aQB2Jm4mibtlbWL+1By+FE=; b=fYmPkXkecdt3GVCsoGKhHC AG8aKoNyhWsq2eWtSPYGoDH5vkY1I7NAvC/owKTnnqPDPDv3WfmydqCXmrc1fhND 2n1v+cVxyI3T1QjQ6Yx1jeYNGcW+0p7obMhuaAliy003h/qnoO9NdLAr+HD0rIyr Rv++8km9BxHu/g9l+sFslOOY1V16qWibEYB7xi86foP0+/uNbtfM/ktE2PM2sxEW M0npcTAABy7O4qGJrGSwWtq+sBsj594KoWOTjpFpydQQ3v6i0EIuRYsFJFhc8OqS JvvKh1s1kEocOzzcHpkQzAiPifHZxNoqI5Dd+kNuOJLU/PuBgc9Vyh7VSTuNn04A == 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 33B3BE508E; Mon, 9 Apr 2018 10:14:46 -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: <089767b9-d84c-498f-6ad7-412e054d592a@aklaver.com> Date: Mon, 9 Apr 2018 07:14:45 -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. https://www.postgresql.org/docs/10/static/sql-copy.html File Formats Text Format " \n Newline (ASCII 10) 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. ... COPY TO will terminate each row with a Unix-style newline (“\n”). " > > 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. > > Thank you and best regards, > > > Đỗ Ngọc Trí*Cường*(Mr.) | *Software Development Department*| +84 28 3715 > 5325 -- Adrian Klaver adrian.klaver@aklaver.com