Re: Emitting JSON to file using COPY TO
Daniel Verite <daniel@manitou-mail.org>
From: "Daniel Verite" <daniel@manitou-mail.org>
To: "Andrew Dunstan" <andrew@dunslane.net>
Cc: Masahiko Sawada <sawada.mshk@gmail.com>,
Jian He
<jian.universality@gmail.com>,
Joe Conway <mail@joeconway.com>,
Junwang Zhao
<zhjwpku@gmail.com>,
Florents Tselai
<florents.tselai@gmail.com>,
Andrey M. Borodin <x4mmm@yandex-team.ru>,
Dean Rasheed
<dean.a.rasheed@gmail.com>,
Davin Shearer <davin@apache.org>,
PostgreSQL development <pgsql-hackers@postgresql.org>
Date: 2026-03-18T14:37:23Z
Lists: pgsql-hackers, pgsql-general
Andrew Dunstan wrote:
> Here's a v30 set that I hope fixes these issues.
Currently there's no difference in output between the null
json value and the SQL null.
postgres=# create table tbl (j jsonb);
CREATE TABLE
postgres=# insert into tbl values('null');
INSERT 0 1
postgres=# insert into tbl values(null);
INSERT 0 1
postgres=# table tbl;
j
------
null
(2 rows)
postgres=# copy tbl to stdout with (format json);
{"j":null}
{"j":null}
If we had to reload this file, we could not determine which
kind of null we had even though they are different at the SQL
level:
postgres=# select null::jsonb is distinct from 'null'::jsonb;
?column?
----------
t
Does it have to be that way or are there valid distinct outputs
that we could use to avoid this ambiguity?
Best regards,
--
Daniel Vérité
https://postgresql.verite.pro/
Commits
-
Add option force_array for COPY JSON FORMAT
- 4c0390ac53b7 19 (unreleased) landed
-
json format for COPY TO
- 7dadd38cda95 19 (unreleased) landed
-
introduce CopyFormat, refactor CopyFormatOptions
- a2145605ee3d 19 (unreleased) landed
-
Doc: add IDs to copy.sgml's <varlistentry> and <refsect1>
- e4018f891dec 19 (unreleased) cited
-
Refactor COPY TO to use format callback functions.
- 2e4127b6d2d8 18.0 cited