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.96) (envelope-from ) id 1w3EuJ-0012Md-1l for pgsql-hackers@arkaria.postgresql.org; Thu, 19 Mar 2026 15:03:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w3EtI-000Uak-2A for pgsql-hackers@arkaria.postgresql.org; Thu, 19 Mar 2026 15:02:29 +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.96) (envelope-from ) id 1w3EtI-000Uab-0S for pgsql-hackers@lists.postgresql.org; Thu, 19 Mar 2026 15:02:28 +0000 Received: from mail-vk1-xa33.google.com ([2607:f8b0:4864:20::a33]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w3EtF-00000000132-3yOd for pgsql-hackers@postgresql.org; Thu, 19 Mar 2026 15:02:27 +0000 Received: by mail-vk1-xa33.google.com with SMTP id 71dfb90a1353d-5637886c92aso504314e0c.0 for ; Thu, 19 Mar 2026 08:02:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dunslane-net.20230601.gappssmtp.com; s=20230601; t=1773932544; x=1774537344; darn=postgresql.org; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :from:references:cc:to:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=VTfunmDAS+7psVO3hSubiId9LdkmrVThYDTg7zM4f2A=; b=C346bc0KcWIg3J+KBNu3HrXyNtKgkxgQKsKtpoNRycU/Gieek33LY3z4nOqqmj7HAY 78q562m0T//RiQGUmv5DikHFVNnNQeuJ7UiuKhDL2sUg/MBXmp6LOyvI6XjnFIz4ArDZ Br8pMZL8ar8nJQOrykok2UqDBs5wVaYtc4Vcf1B9oLuGESvx4Tbcyjl+nCyyO9+cVN3N Wcd2JXFwFz0suSWb6uyNXBEc6gIdU23ZaEOZ0QFamZZR8kSyZoB6xk5Z34UwU55kk97/ FvwVr16x2J5kT3pAm8xDxypEZ7UwzQM+EZdA0jtJAFSej9ilc9hif5qPDSfGFkwMsriw 7zSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773932544; x=1774537344; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :from:references:cc:to:subject:user-agent:mime-version:date :message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=VTfunmDAS+7psVO3hSubiId9LdkmrVThYDTg7zM4f2A=; b=VaiixHreBzgH2krrLSMfrbZgbLZIt79HcZmmHqNpNNC8Lq5Yz5BXGCxoFjSdwygOpU krU3tr0/Kh+z4ezCnuC4cOPqGnEGN2qcDI+8ikcOggibPRuQat335IqlbxY+df0E7mM5 EQ/xXJaqyBIV5chBzPbXf9rVS4FxngKXVLqtUxZ9JAabmb9e5GR/QWAg0uLgD/Pt3TDd e0zwhV4tyNgXP9r3U+uKy29ILuJPO+r49q0436em7fwwrfcTnCs55Ut8RQl2qO7vE3Xg b90tawyo8giAdcsphocbC2VInjSd00DJ0eXbyaEId44xp2fu+xoehPIw27hYldbsoy5R Pqyw== X-Forwarded-Encrypted: i=1; AJvYcCUIwHgHcGcRme9glDzgb7dhihXphcdN+TrlWxAnneOyAn0aclixEA0G8In3eyxZw10W64Y8zMaKjgIR04dD@postgresql.org X-Gm-Message-State: AOJu0Yw65R3K5saROFke/WavjPtK9fHl+fK4Ve+KA2mjitcRKEyavvQS nFG3rD+hn6nqbRTAeN08txPaBP7vBTthDUvQJsIgyUnH6ISrB5sMMzhS1Vho2QdXiQU= X-Gm-Gg: ATEYQzyf3xxZsFgNsOETqkq/hZT2A+jVCefueJy2bLAf4bra1pKmcmKG8tMee5Xup7l xjrJ04yBwVCXGC3SJLtxNat1wEd2tX4tA5svS2PH5Bd9mPHN5nJ8AmbonH+41fr/9Do/0UfpS/9 9nY1GZcTrATcH1IxW/DXHYB7sTactSxplAOKozKlSlfmZxBd2ZMZUgYigEsOJlSIKoH7ReTr9L3 YD5ZXnmzi1OE0xkH1Y2qrazDYfudcj9FF5yXxKSZgxzprPhlqjogqQTkpyezOb9OGMVSQeFqnJO w+GFpK++0Oymj92xiZPKKtpCsZBGiR5czQOzhFlnDQk1x12ziw+khN41Hlns0gi/Aru9xoWAeVV Wf3xB8xMZ4ZASTog53sgFtKZ+6N3ij03Vw4Ek2nVZMoTRPWRMckenyagKgn4HMjjdXonVYrYxqS YMqik5KlH/Do8TolnVEvoK4JeSljP5lg== X-Received: by 2002:a05:6122:2521:b0:55f:c318:1afa with SMTP id 71dfb90a1353d-56ba70824f7mr3999912e0c.6.1773932543872; Thu, 19 Mar 2026 08:02:23 -0700 (PDT) Received: from ?IPV6:2605:a601:a6b0:500::1cb? ([2605:a601:a6b0:500::1cb]) by smtp.googlemail.com with ESMTPSA id a1e0cc1a2514c-9510325cfafsm2904515241.2.2026.03.19.08.02.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 19 Mar 2026 08:02:23 -0700 (PDT) Message-ID: <8428eb0f-f467-4cbd-a510-5be4f29b9ad7@dunslane.net> Date: Thu, 19 Mar 2026 11:02:21 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Emitting JSON to file using COPY TO To: jian he , Daniel Verite Cc: Masahiko Sawada , Joe Conway , Junwang Zhao , Florents Tselai , "Andrey M. Borodin" , Dean Rasheed , Davin Shearer , PostgreSQL development References: <964a3377-d957-4a06-ad02-8228aefa65fc@dunslane.net> From: Andrew Dunstan Content-Language: en-US Autocrypt: addr=andrew@dunslane.net; keydata= xsBNBE7KWFkBCAClridxur2AIc7eW2AR7izbfp3EnNefie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cxY6+k/8TEk+C4R+M6w7o2PLGOjdZ +kPiUcw5H85zf/yZJwQXzisXaNduwWB6Vads9YC9dj6kPR1c4VGRqAaYL++LAEOqrlvm2Tvq QqZRtnEAEQEAAcLAfAQYAQgAJgIbDBYhBOQ+WEYd/Hy/RGkVpZn6f8tZ/DuBBQJoGNI2BQkd EODdAAoJEJn6f8tZ/DuBfw0IAKTsfD40teP/pp+bsLLMSxPXUYrrprTj7WFB5v61p6dkpSr/ qXmMlyahdxQFaPmfVgVirB1Vk/kHiWNnnGjfUV9nB2Zg9LI0Xb9/ts3LsUiRWXzG3tkMY6XL vsVOxW4XFRND9l2q+WW93aZ1DZl+fqWfYgMvsusFRhmGFOKTRfKPta2Pkv+AhA24N4+PrR5p bU4k2MO8PAGiK8eaYKGFG1bHKuAvoDoF7WXJ3FHxuWqLnKEt4dfOLm5pAe3zq1Lt6q8azT9i QWGpSAK5vQUWQHBHpiDjdPeqKZ6HiAXIIKfSmb+jrvXBqoP+D6/K7rUjG2aXiRtTIAXms9sm VRu7cmw= 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 2026-03-18 We 9:58 PM, jian he wrote: > On Wed, Mar 18, 2026 at 10:37 PM Daniel Verite wrote: >> Currently there's no difference in output between the null >> json value and the SQL null. >> >> postgres=# create table tbl (j jsonb); >> postgres=# insert into tbl values('null'); >> postgres=# insert into tbl values(null); >> postgres=# copy tbl to stdout with (format json); >> {"j":null} >> {"j":null} >> >> Does it have to be that way or are there valid distinct outputs >> that we could use to avoid this ambiguity? >> > This is an existing (quite old) behavior of > composite_to_json->datum_to_json_internal, IMHO. > > ``` > if (is_null) > { > appendBinaryStringInfo(result, "null", strlen("null")); > return; > } > ``` > produce the same results as > ``` > case JSONTYPE_JSON: > /* JSON and JSONB output will already be escaped */ > outputstr = OidOutputFunctionCall(outfuncoid, val); > appendStringInfoString(result, outputstr); > pfree(outputstr); > break; > ``` > > Therefore I intended to document it as below: > > > JSON Format > > When the json format is used, data is > exported with one JSON object per line, > where each line corresponds to a single record. > The json format has no standard way to > distinguish between an SQL NULL and a JSON > null literal. > In the examples that follow, the following table containing JSON > data will be used: > > CREATE TABLE my_test (a jsonb, b int); > INSERT INTO my_test VALUES ('null', 1), (NULL, 1); > > > When exporting this table using the json format: > > COPY my_test TO STDOUT (FORMAT JSON); > > In the resulting output, both the SQL NULL and > the JSON null are rendered identically: > > {"a":null,"b":1} > {"a":null,"b":1} > > > > > > > what do you think? > > > I can live with that, if others can. cheers andrew -- Andrew Dunstan EDB: https://www.enterprisedb.com