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 1rilHx-001box-8y for pgsql-hackers@arkaria.postgresql.org; Sat, 09 Mar 2024 01:14:13 +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 1rilHj-00H9gc-7E for pgsql-hackers@arkaria.postgresql.org; Sat, 09 Mar 2024 01:13:59 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rilHi-00H9gU-Rk for pgsql-hackers@lists.postgresql.org; Sat, 09 Mar 2024 01:13:59 +0000 Received: from mail-oa1-x2f.google.com ([2001:4860:4864:20::2f]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rilHY-003XTr-Bj for pgsql-hackers@postgresql.org; Sat, 09 Mar 2024 01:13:58 +0000 Received: by mail-oa1-x2f.google.com with SMTP id 586e51a60fabf-221a9e5484aso517916fac.0 for ; Fri, 08 Mar 2024 17:13:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709946826; x=1710551626; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=lGuxLKPnb3unFREBsBECmITT00CgX79A4gQkfF5WDic=; b=RPMQgtJFcAAOm4BR5pju+x2mWzFzHW/U1I8gftKsqJY0s6uf1bmBTXvBIawFm6RqPZ pV+2z1vVft3HUljfNWvGmEu9JIDXRe0E8X5GoCeyBomtvbABs8PEhT2qjNaI0h43bhcT sIPq8IXxlD7MwY/Znu4LaayFEg2ByIrNZqBQcbWPiLKaAvEspyaJj42GHlHjk2owAN4s xGSSNdALUGeCY+W+fGzcl/cEXX6cuz6PeCUfQjG/0xjGzwxPoHitwEYXmMJi8zHvPaxa wuRmAPAyZGi2j+8MakpSMVxeh5yC8iBE74aILmyL6Zbr+5Higt8B26l2InN4NlDytGhP OP/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709946826; x=1710551626; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lGuxLKPnb3unFREBsBECmITT00CgX79A4gQkfF5WDic=; b=dk9v/1D21rGpV1tmJbvLyZfKSMUSlBqf0QtFtI5utOrmPoW5GGwTniV81G1S7LvK1r AVknUEfntb+aMRHA+PjFNQOJm+PuaajuTkzoKRKy4/xICo0AHMyCGphL7NUJReRJCgHd rikt9qBnOQRt1HFC80iEMo/dCbWKMJHuYpPy32uN7E7VB1jzeESXDXhlszksRxklN0ER x4Q+9GvZBNrxoDBq2E/CNvq+stBHDdriaNw3jFaFkl1fKRPXEIis6nE37ar1AH/mYZj/ 7ydGGIM7ddp5UYaEMCzawB/VGEIBbEktqGNuuOj+wAfd853UCcWNjb9wc+TKPe7ANmtE rgEw== X-Forwarded-Encrypted: i=1; AJvYcCWVtRuNGwcWH+Zxe2+Na1m4U2+GX7K11g+rvAKxe9k89pIPkzQM4BPF+BvVgmtHnxLegyJq1m80fze+CnGkcXg7mqQG+L7vMbpWqYMR X-Gm-Message-State: AOJu0Yyjq6ozxOrezCLmnO4dgv84m44PgooVvbDETLFfgebMIRNzeVvn QpCfzP2JUoyeUvhl+BbUpy+WLZW6AMP5CuLrHq3PwgsIqUrWcG4u06fNZBDT/bU80tAHdhfohlm ICEx4eCE3/mXv46st8Gbyq963o6Q= X-Google-Smtp-Source: AGHT+IEpDC/xCPFi6hyaZf68LbSgt+m+sbEmCCmbIeGqyHGsSF8VomMQB+E6ESSml6sXA8k72/o4j4HsDNqnyChlwHM= X-Received: by 2002:a05:6870:65a1:b0:21e:be10:f39d with SMTP id fp33-20020a05687065a100b0021ebe10f39dmr772137oab.46.1709946825948; Fri, 08 Mar 2024 17:13:45 -0800 (PST) MIME-Version: 1.0 References: <8620df11-96e4-4ca3-8f3c-33a479260961@joeconway.com> <4162f7f7-6fd6-4720-98e2-89f80e3de2ed@joeconway.com> <153b71b8-b6fb-4930-aaff-a7334cb3f6d6@joeconway.com> <8ef5f5d6-38db-4624-8eef-2d96c9eba9d4@joeconway.com> In-Reply-To: <8ef5f5d6-38db-4624-8eef-2d96c9eba9d4@joeconway.com> From: jian he Date: Sat, 9 Mar 2024 09:13:34 +0800 Message-ID: Subject: Re: Emitting JSON to file using COPY TO To: Joe Conway Cc: "Andrey M. Borodin" , Dean Rasheed , Daniel Verite , Andrew Dunstan , Davin Shearer , PostgreSQL-development Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sat, Mar 9, 2024 at 2:03=E2=80=AFAM Joe Conway wrot= e: > > On 3/8/24 12:28, Andrey M. Borodin wrote: > > Hello everyone! > > > > Thanks for working on this, really nice feature! > > > >> On 9 Jan 2024, at 01:40, Joe Conway wrote: > >> > >> Thanks -- will have a look > > > > Joe, recently folks proposed a lot of patches in this thread that seem = like diverted from original way of implementation. > > As an author of CF entry [0] can you please comment on which patch vers= ion needs review? > > > I don't know if I agree with the proposed changes, but I have also been > waiting to see how the parallel discussion regarding COPY extensibility > shakes out. > > And there were a couple of issues found that need to be tracked down. > > Additionally I have had time/availability challenges recently. > > Overall, chances seem slim that this will make it into 17, but I have > not quite given up hope yet either. Hi. summary changes I've made in v9 patches at [0] meta: rebased. Now you need to use `git apply` or `git am`, previously copyto_json.007.diff, you need to use GNU patch. at [1], Dean Rasheed found some corner cases when the returned slot's tts_tupleDescriptor from ` ExecutorRun(cstate->queryDesc, ForwardScanDirection, 0, true); processed =3D ((DR_copy *) cstate->queryDesc->dest)->processed; ` cannot be used for composite_to_json. generally DestReceiver->rStartup is to send the TupleDesc to the DestReceiv= er, The COPY TO DestReceiver's rStartup function is copy_dest_startup, however copy_dest_startup is a no-op. That means to make the final TupleDesc of COPY TO (FORMAT JSON) operation bullet proof, we need to copy the tupDesc from CopyToState's queryDesc. This only applies to when the COPY TO source is a query (example: copy (select 1) to stdout), not a table. The above is my interpretation. at [2], Masahiko Sawada made several points. Mainly split the patch to two, one for format json, second is for options force_array. Splitting into two is easier to review, I think. My changes also addressed all the points Masahiko Sawada had mentioned. [0] https://postgr.es/m/CACJufxHd6ZRmJJBsDOGpovaVAekMS-u6AOrcw0Ja-Wyi-0kGtA= @mail.gmail.com [1] https://postgr.es/m/CAEZATCWh29787xf=3D4NgkoixeqRHrqi0Qd33Z6_-F8t2dZ0yL= CQ@mail.gmail.com [2] https://postgr.es/m/CAD21AoCb02zhZM3vXb8HSw8fwOsL+iRdEFb--Kmunv8PjPAWjw= @mail.gmail.com