| From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
|---|---|
| To: | Ayush Tiwari <ayushtiwari(dot)slg01(at)gmail(dot)com> |
| Cc: | pgsql-hackers(at)postgresql(dot)org, andrew(at)dunslane(dot)net |
| Subject: | Re: [PATCH] Reject ENCODING option for COPY TO FORMAT JSON |
| Date: | 2026-04-20 13:39:44 |
| Message-ID: | 196325.1776692384@sss.pgh.pa.us |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Ayush Tiwari <ayushtiwari(dot)slg01(at)gmail(dot)com> writes:
> COPY TO FORMAT JSON silently accepts the ENCODING option but doesn't
> perform encoding conversion(?) CopyToJsonOneRow() sends the output of
> composite_to_json() via CopySendData() without calling
> pg_server_to_any(), unlike the text and CSV paths.
> COPY t TO '/tmp/out.json' WITH (FORMAT json, ENCODING 'LATIN1');
> On a UTF-8 server this produces UTF-8 output, not LATIN1.
Seems to me the correct thing here is to make it work like the other
cases, ie perform pg_server_to_any(). I have exactly no sympathy for
the argument about the RFC saying it must be UTF-8, not least because
that's not in fact what is implemented (what if the server encoding
isn't UTF-8?).
Rejecting this option altogether doesn't improve anything, not
functionally, not specs-compliance-wise, nor according to the
principle of least surprise.
> The attached patch rejects the explicit ENCODING option for JSON
> mode, consistent with how DELIMITER, NULL, DEFAULT, and HEADER are
> already rejected. The implicit client_encoding case is a separate
> design question (should COPY TO JSON always emit UTF-8 regardless
> of client_encoding?) that maybe we should address separately and not as
> part of v19.
No, you don't get to punt this till later. Once we ship v19 there's
going to be a strong expectation of backwards compatibility.
The idea of sending UTF-8 to a client that's set client_encoding to
something else would be risible, if it weren't a security hazard.
regards, tom lane
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Antonin Houska | 2026-04-20 13:46:13 | Re: Adding REPACK [concurrently] |
| Previous Message | Xuneng Zhou | 2026-04-20 13:03:41 | Re: First draft of PG 19 release notes |