]> git.ipfire.org Git - thirdparty/postgresql.git/commit
json format for COPY TO
authorAndrew Dunstan <andrew@dunslane.net>
Mon, 16 Mar 2026 20:50:24 +0000 (16:50 -0400)
committerAndrew Dunstan <andrew@dunslane.net>
Fri, 20 Mar 2026 12:40:04 +0000 (08:40 -0400)
commit7dadd38cda95bf5bc0c4715d9ab71766d1693379
tree23ce6394b498afe6f5ed06a460ebb9c79b7cba51
parenta2145605ee3d92faccd769010059b110c44104ff
json format for COPY TO

This introduces the JSON format option for the COPY TO command, allowing
users to export query results or table data directly as a stream of JSON
objects (one per line, NDJSON style).

The JSON format is currently supported only for COPY TO operations; it
is not available for COPY FROM.

JSON format is incompatible with some standard text/CSV formatting
options, including HEADER, DEFAULT, NULL, DELIMITER, FORCE QUOTE,
FORCE NOT NULL, and FORCE NULL.

Column list support is included: when a column list is specified, only
the named columns are emitted in each JSON object.

Regression tests covering valid JSON exports and error handling for
incompatible options have been added to src/test/regress/sql/copy.sql.

Author: Joe Conway <mail@joeconway.com>
Author: jian he <jian.universality@gmail.com>
Co-Authored-By: Andrew Dunstan <andrew@dunslane.net>
Reviewed-by: Andrey M. Borodin <x4mmm@yandex-team.ru>
Reviewed-by: Dean Rasheed <dean.a.rasheed@gmail.com>
Reviewed-by: Daniel Verite <daniel@manitou-mail.org>
Reviewed-by: Davin Shearer <davin@apache.org>
Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com>
Reviewed-by: Alvaro Herrera <alvherre@alvh.no-ip.org>
Reviewed-by: Junwang Zhao <zhjwpku@gmail.com>
Discussion: https://postgr.es/m/CALvfUkBxTYy5uWPFVwpk_7ii2zgT07t3d-yR_cy4sfrrLU%3Dkcg%40mail.gmail.com
Discussion: https://postgr.es/m/6a04628d-0d53-41d9-9e35-5a8dc302c34c@joeconway.com
doc/src/sgml/ref/copy.sgml
src/backend/commands/copy.c
src/backend/commands/copyto.c
src/backend/parser/gram.y
src/backend/utils/adt/json.c
src/bin/psql/tab-complete.in.c
src/include/commands/copy.h
src/include/utils/json.h
src/test/regress/expected/copy.out
src/test/regress/sql/copy.sql