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 1rAci8-007RjM-8S for pgsql-hackers@arkaria.postgresql.org; Tue, 05 Dec 2023 21:12:08 +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 1rAci6-006Cad-Kf for pgsql-hackers@arkaria.postgresql.org; Tue, 05 Dec 2023 21:12:06 +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 1rAci6-006CaV-BZ for pgsql-hackers@lists.postgresql.org; Tue, 05 Dec 2023 21:12:06 +0000 Received: from mail-qk1-x734.google.com ([2607:f8b0:4864:20::734]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rAci3-008yai-BB for pgsql-hackers@postgresql.org; Tue, 05 Dec 2023 21:12:05 +0000 Received: by mail-qk1-x734.google.com with SMTP id af79cd13be357-77bcbc14899so411487985a.1 for ; Tue, 05 Dec 2023 13:12:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dunslane-net.20230601.gappssmtp.com; s=20230601; t=1701810722; x=1702415522; 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=M4feoTZwkj7pzhe5ZU+koj3e88PNnFktIo3lVfXOh2M=; b=hbXARA8SpFTOJNc6tgbfYnAKzZoA+PfjZH2Rh26HJp29g8loQEbN3roAs2/IFHAoA6 Y1f2ISdzNEA6NDdjKjB1w1LtxI9HjTdcx7KSSwt5GHubacUsyKqDVHti3g66o1Eb2lsy oJXXTWso70L8HDM9AceupKfYIkh9af8uz3gzlEz2qZ/haMMkYYAZcjrmilWLqvCqbRjo ITdRVrFwUQQvdWfZ4StgnXBJ6xttrDS9//9c3JF9S7WmCqJrxMcz5qxwxzxzGTBl+CPl mTFjXQ2Erp/TsJL3HHDU571Wf7oTI/cu1pJeyhe6jtZ/fqskFcODg6f5V7BWXwZd+uz5 mHaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701810722; x=1702415522; 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=M4feoTZwkj7pzhe5ZU+koj3e88PNnFktIo3lVfXOh2M=; b=iRk/aVUFwd7Pq0hrc1EEgLHZkXn3YVnTY7JeuVPmwgFGM6Ce/1K7u0eOb3+y+MCTZl BQ8dFQKM4yB6qTfyepYJWQx4v+uVXygB2IpZxHgWyexrHFHc92ePHgDMDh4eFKPzQepp hQQEckSDbnxiOUw0tbfcw0EWy++NnjawOvYBVzPwCuSsyzB+Bje+4H6gxhDHBqrD1FjH 3NqHKBwABN65mQRZzjhb8AtCTV2hV9nz9ikl4bcpMSBJsXePddXLgsPJtJQTTtJkFxtN 6wtt6dpLgPQ3zOaWWaPr/qfV0qSe57dPQrst7yrE/JLyNt+ccPURDkq7ioQ9PSiRZExi FUbA== X-Gm-Message-State: AOJu0Yw3mqkk3g4AnTwiqh3hqZuDcm/Xcfvs3hYuF2Wuaac7PHKrhDy2 jPe6swo+01cOkXmZUAFM4f0Jxg== X-Google-Smtp-Source: AGHT+IEQdLv/mLxI1Lbp2TmxFbOH6kzjFjDtcvWAJuYrravLaMIuzUUerJOD0aZBgyJMnCEoI8d2sw== X-Received: by 2002:a05:620a:89d:b0:77d:bcf0:81cf with SMTP id b29-20020a05620a089d00b0077dbcf081cfmr2082441qka.26.1701810721954; Tue, 05 Dec 2023 13:12:01 -0800 (PST) Received: from ?IPV6:2605:a601:91bc:f600::2bb? ([2605:a601:91bc:f600::2bb]) by smtp.googlemail.com with ESMTPSA id ou17-20020a05620a621100b0077d72f820adsm5354864qkn.115.2023.12.05.13.12.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 05 Dec 2023 13:12:01 -0800 (PST) Message-ID: <22d9e40d-7de2-1301-3970-16136f7732a6@dunslane.net> Date: Tue, 5 Dec 2023 16:12:00 -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: <9c77b6fa-ee88-b2e6-0fa7-4fc81721da35@dunslane.net> <41dcba92-1075-e5e5-cb99-36711abf6cec@dunslane.net> <5c84b70b-ba18-c45d-dbbe-612fa229b2ce@dunslane.net> <398c22f6-4299-4b17-80bf-2f14f4afd592@joeconway.com> <46cc4507-a0d9-4044-b2ce-5a8bca8015c0@joeconway.com> <2554e520-e103-8978-dcb5-807dfeb77402@dunslane.net> 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-05 Tu 16:02, Joe Conway wrote: > On 12/5/23 15:55, Andrew Dunstan wrote: >> >> On 2023-12-05 Tu 14:50, Davin Shearer wrote: >>> Hi Joe, >>> >>> In reviewing the 005 patch, I think that when used with FORCE ARRAY, >>> we should also _imply_ FORCE ROW DELIMITER.  I can't envision a use >>> case where someone would want to use FORCE ARRAY without also using >>> FORCE ROW DELIMITER.  I can, however, envision a use case where >>> someone would want FORCE ROW DELIMITER without FORCE ARRAY, like >>> maybe including into a larger array.  I definitely appreciate these >>> options and the flexibility that they afford from a user perspective. >>> >>> In the test output, will you also show the different variations with >>> FORCE ARRAY and FORCE ROW DELIMITER => {(false, false), (true, >>> false), (false, true), (true, true)}? Technically you've already >>> shown me the (false, false) case as those are the defaults. >>> >>> >> >> I don't understand the point of FORCE_ROW_DELIMITER at all. There is >> only one legal delimiter of array items in JSON, and that's a comma. >> There's no alternative and it's not optional. So in the array case you >> MUST have commas and in any other case (e.g. LINES) I can't see why you >> would have them. > > The current patch already *does* imply row delimiters in the array > case. It says so here: > 8<--------------------------- > +    > + FORCE_ARRAY > +     > +      > +       Force output of array decorations at the beginning and end of > output. > +       This option implies the FORCE_ROW_DELIMITER > +       option. It is allowed only in COPY TO, and > only > +       when using JSON format. > +       The default is false. > +      > 8<--------------------------- > > and it does so here: > 8<--------------------------- > +         if (opts_out->force_array) > +             opts_out->force_row_delimiter = true; > 8<--------------------------- > > and it shows that here: > 8<--------------------------- > + copy copytest to stdout (format json, force_array); > + [ > +  {"style":"DOS","test":"abc\r\ndef","filler":1} > + ,{"style":"Unix","test":"abc\ndef","filler":2} > + ,{"style":"Mac","test":"abc\rdef","filler":3} > + ,{"style":"esc\\ape","test":"a\\r\\\r\\\n\\nb","filler":4} > + ] > 8<--------------------------- > > It also does not allow explicitly setting row delimiters false while > force_array is true here: > 8<--------------------------- > > +         if (opts_out->force_array && > +             force_row_delimiter_specified && > +             !opts_out->force_row_delimiter) > +             ereport(ERROR, > +                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), > +                      errmsg("cannot specify FORCE_ROW_DELIMITER > false with FORCE_ARRAY true"))); > 8<--------------------------- > > Am I understanding something incorrectly? But what's the point of having it if you're not using FORCE_ARRAY? cheers andrew -- Andrew Dunstan EDB: https://www.enterprisedb.com