Re: Emitting JSON to file using COPY TO

From: "Daniel Verite" <daniel(at)manitou-mail(dot)org>
To: "Andrew Dunstan" <andrew(at)dunslane(dot)net>
Cc: Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>, Jian He <jian(dot)universality(at)gmail(dot)com>, Joe Conway <mail(at)joeconway(dot)com>, Junwang Zhao <zhjwpku(at)gmail(dot)com>, Florents Tselai <florents(dot)tselai(at)gmail(dot)com>, Andrey M(dot) Borodin <x4mmm(at)yandex-team(dot)ru>, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Davin Shearer <davin(at)apache(dot)org>, PostgreSQL development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Emitting JSON to file using COPY TO
Date: 2026-03-18 14:37:23
Message-ID: fc61429f-76a1-4385-a2bd-999967da306f@manitou-mail.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

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/

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Greg Hennessy 2026-03-18 15:56:20 Re: help debugging an issue with selectivity
Previous Message Tom Lane 2026-03-18 02:37:35 Re: help debugging an issue with selectivity

Browse pgsql-hackers by date

  From Date Subject
Next Message ls7777 2026-03-18 14:42:59 Re: Patch for migration of the pg_commit_ts directory
Previous Message Andrei Lepikhov 2026-03-18 14:36:31 Re: Read-only connection mode for AI workflows.