Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r9sRV-002vdw-1G for pgsql-hackers@arkaria.postgresql.org; Sun, 03 Dec 2023 19:47:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1r9sRR-00DGSM-8o for pgsql-hackers@arkaria.postgresql.org; Sun, 03 Dec 2023 19:47:49 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r9sRQ-00DGSE-Ko for pgsql-hackers@lists.postgresql.org; Sun, 03 Dec 2023 19:47:48 +0000 Received: from mail-oi1-x22a.google.com ([2607:f8b0:4864:20::22a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1r9sRN-008dC9-6Z for pgsql-hackers@postgresql.org; Sun, 03 Dec 2023 19:47:46 +0000 Received: by mail-oi1-x22a.google.com with SMTP id 5614622812f47-3b8bb35cbc3so393333b6e.3 for ; Sun, 03 Dec 2023 11:47:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dunslane-net.20230601.gappssmtp.com; s=20230601; t=1701632864; x=1702237664; darn=postgresql.org; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=SWC8ITNAEzkuDlU6glAAjOvt+jpefMsr6k8JLouYiC8=; b=GSzd7lKJ1lBGr7MEXSdWWM7OH8usxHmgLPKjjpWUrTnDwbJZ8vTq/3bsRm2YzasmeE yGR5Olo6Jor0upS+q+1zNbZrcSSkri1LzR/0oQ7kXWq2QXIUal3B3Dy9+CCH7ptyUaOK OjE1iMuatT6nw/Wbi+A7HEBFRQIow1bln4Cpw0E1cgs/NJTRzcleWv+H8OOUKCaJjyBs 53YXnwJ0Er8bWQzicqqy2bdIjDlF48EOSP7QYV6ARbCzbdyOx8UGxdKVTXi6WFeO3mv+ 8RR++oKzkH/5MRYX+h5wGpSR/wyfOvi0cVXG0PSHRvcvBLlqu/LUOOPglDKuG9IPMEgI Dvvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701632864; x=1702237664; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=SWC8ITNAEzkuDlU6glAAjOvt+jpefMsr6k8JLouYiC8=; b=fczz2v/CN57UZf/XUKS7QCX5nk9FNWMVl1lW7I8uqNdKIvFSWADN5Ofj8CpGH03tWK unvC85ULdveql4Fv3m1n3l4NVI4253xsuGt3tMR92sT38lICBiwZG3BzSmY3VLS6cts7 EeGs1ko8+1lXx+obW44PwlD1MhRys0/+4ym7KLX3U5n/Tz7O4s2WksnMaXarKGq3BoCu wTrADQrqHAmGSr/ff8jubLaqXdZSvpgAWcFwNWg9N5m2twtZhUOeDCbfoYXjpqAV35Xv ot2SgeDHplARpTb7YChRNsXpKsPnsJ4F2fU5UtyWd6YM4tyw7BlI7c5BZVNCPlUKKPfS AHdg== X-Gm-Message-State: AOJu0YxN9DwxxXBbSnx3fyZioxTINEq8pe7M30+DfcAEEkThflISTpdB tIxFykyRhUlpzB4RI5w/6FyOWg== X-Google-Smtp-Source: AGHT+IG48mJsBPhzuruaVnfhIM4bzn8tLSui2mjoTXTV1BUvsJSfQGc0pGAsSa6VURe+3G4nmn8ucQ== X-Received: by 2002:a05:6808:1150:b0:3b8:b063:a1b3 with SMTP id u16-20020a056808115000b003b8b063a1b3mr4885703oiu.61.1701632863987; Sun, 03 Dec 2023 11:47:43 -0800 (PST) Received: from ?IPV6:2605:a601:91bc:f600::2bb? ([2605:a601:91bc:f600::2bb]) by smtp.googlemail.com with ESMTPSA id u5-20020ae9c005000000b0077d93c7c785sm3604287qkk.119.2023.12.03.11.47.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 03 Dec 2023 11:47:43 -0800 (PST) Message-ID: Date: Sun, 3 Dec 2023 14:47:42 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: Emitting JSON to file using COPY TO Content-Language: en-US To: Joe Conway , Davin Shearer , PostgreSQL-development References: <3853387.1701096982@sss.pgh.pa.us> <3a98decf-3fe3-4b49-9b68-fda01338872c@sedlakovi.org> <24e3ee88-ec1e-421b-89ae-8a47ee0d2df1@joeconway.com> <8c88da85-c197-4765-96f8-a9a1c78305a6@joeconway.com> From: Andrew Dunstan In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2023-12-03 Su 12:11, Joe Conway wrote: > On 12/3/23 11:03, Joe Conway wrote: >>   From your earlier post, regarding constructing the aggregate -- not >> extensive testing but one data point: >> 8<-------------------------- >> test=# copy foo to '/tmp/buf' (format json, force_array); >> COPY 10000000 >> Time: 36353.153 ms (00:36.353) >> test=# copy (select json_agg(foo) from foo) to '/tmp/buf'; >> COPY 1 >> Time: 46835.238 ms (00:46.835) >> 8<-------------------------- > > Also if the table is large enough, the aggregate method is not even > feasible whereas the COPY TO method works: > 8<-------------------------- > test=# select count(*) from foo; >   count > ---------- >  20000000 > (1 row) > > test=# copy (select json_agg(foo) from foo) to '/tmp/buf'; > ERROR:  out of memory > DETAIL:  Cannot enlarge string buffer containing 1073741822 bytes by 1 > more bytes. > > test=# copy foo to '/tmp/buf' (format json, force_array); > COPY 20000000 > 8<-------------------------- None of this is surprising. As I mentioned, limitations with json_agg() are why I support the idea of this patch. cheers andrew -- Andrew Dunstan EDB: https://www.enterprisedb.com