Re: COPY JSON: use trailing commas in FORCE_ARRAY output

From: Daniel Gustafsson <daniel(at)yesql(dot)se>
To: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: COPY JSON: use trailing commas in FORCE_ARRAY output
Date: 2026-05-06 08:23:53
Message-ID: B774FE54-19BB-4250-AF2E-967460816C1F@yesql.se
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> On 6 May 2026, at 08:40, Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> wrote:

> I was surprised by the comma placement. It is valid JSON, but it looks quite uncommon.

It might look uncommon, but for very wide lines it's IMHO preferrable to not
have to scroll all the way to the end of the line to know that the line is part
of an array.

> For comparison, the existing json_agg() places commas at the end of the line:

That's true, but json_agg() and COPY TO in ndjson format have different use
cases.

> ..it should not have any performance impact.

It does add branches though, and in one branch use a non-inlined function where
previously it would unconditionally use an inline function. ISTM it would
still be valuable to do performance testing given that COPY is commonly used in
performance sensitive settings.

--
Daniel Gustafsson

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jelte Fennema-Nio 2026-05-06 08:25:23 Re: PSA: Planning to grease protocol connections during 19beta
Previous Message Anthonin Bonnefoy 2026-05-06 08:13:57 Re: Server crash: Use-after-free in AfterTriggerEndQuery()