postgresql/src
Andrew Dunstan 7dc5bbcf22 Apply encoding conversion in COPY TO FORMAT JSON
CopyToJsonOneRow() sent the output of composite_to_json() directly
via CopySendData() without encoding conversion.  The text and CSV
paths convert per-attribute via pg_server_to_any() when
need_transcoding is true, but the JSON path skipped this entirely.

This meant COPY ... TO ... WITH (FORMAT json, ENCODING 'LATIN1') on
a UTF-8 server silently produced UTF-8 output, and COPY TO STDOUT
with a non-UTF-8 client_encoding would send unconverted bytes to
the client.

Apply pg_server_to_any() to the whole JSON buffer after
composite_to_json() returns, converting to the requested file
encoding when it differs from the server encoding.  Tests cover
both the explicit ENCODING option and the implicit case where
file_encoding is inherited from client_encoding.

Introduced by 7dadd38cda (json format for COPY TO).

Author: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Reviewed-by: Andrew Dunstan <andrew@dunslane.net>
Discussion: https://postgr.es/m/CAJTYsWX-jsLzxGRAb-dWnEpGYRPbDYHwce8LctVE92LiDfM2Jw@mail.gmail.com
2026-05-29 21:48:45 -04:00
..
backend Apply encoding conversion in COPY TO FORMAT JSON 2026-05-29 21:48:45 -04:00
bin pg_createsubscriber: Fix cleanup of publisher-side objects after errors 2026-05-27 10:34:17 +09:00
common pg_test_timing: Show additional TSC clock source debug info 2026-05-16 11:51:34 -04:00
fe_utils Pre-beta mechanical code beautification, step 1: run pgindent. 2026-05-13 10:34:17 -04:00
include Constistent naming for datacheckusms processes 2026-05-29 21:26:25 +02:00
interfaces Fix compilation with OpenSSL 4 2026-05-29 21:52:35 +02:00
makefiles Add CONCURRENTLY option to REPACK 2026-04-06 21:55:08 +02:00
pl Pre-beta mechanical code beautification, step 1: run pgindent. 2026-05-13 10:34:17 -04:00
port pg_test_timing: Show additional TSC clock source debug info 2026-05-16 11:51:34 -04:00
template Switch the semaphore API on Solaris to unnamed POSIX. 2026-03-14 14:10:32 -04:00
test Apply encoding conversion in COPY TO FORMAT JSON 2026-05-29 21:48:45 -04:00
timezone Pre-beta mechanical code beautification, step 1: run pgindent. 2026-05-13 10:34:17 -04:00
tools pg_test_timing: Show additional TSC clock source debug info 2026-05-16 11:51:34 -04:00
tutorial Pre-beta mechanical code beautification, step 1: run pgindent. 2026-05-13 10:34:17 -04:00
.gitignore
DEVELOPERS
Makefile Add CONCURRENTLY option to REPACK 2026-04-06 21:55:08 +02:00
Makefile.global.in Update Unicode data to CLDR 48.2 2026-04-13 11:13:36 +02:00
Makefile.shlib Restore AIX support. 2026-02-23 13:34:22 -05:00
meson.build Update copyright for 2026 2026-01-01 13:24:10 -05:00
nls-global.mk Fix update-po for the PGXS case 2025-10-16 20:21:05 +02:00