Allow "COPY table TO" command to copy rows from materialized views.

Fujii Masao <fujii@postgresql.org>

Commit: 534874fac0b34535c9a5ab9257d6574f78423578
Author: Fujii Masao <fujii@postgresql.org>
Date: 2025-04-04T10:32:00Z
Releases: 18.0
Allow "COPY table TO" command to copy rows from materialized views.

Previously, "COPY table TO" command worked only with plain tables and
did not support materialized views, even when they were populated and
had physical storage. To copy rows from materialized views,
"COPY (query) TO" command had to be used, instead.

This commit extends "COPY table TO" to support populated materialized
views directly, improving usability and performance, as "COPY table TO"
is generally faster than "COPY (query) TO". Note that copying from
unpopulated materialized views will still result in an error.

Author: jian he <jian.universality@gmail.com>
Reviewed-by: Kirill Reshke <reshkekirill@gmail.com>
Reviewed-by: David G. Johnston <david.g.johnston@gmail.com>
Reviewed-by: Vignesh C <vignesh21@gmail.com>
Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Discussion: https://postgr.es/m/CACJufxHVxnyRYy67hiPePNCPwVBMzhTQ6FaL9_Te5On9udG=yg@mail.gmail.com

Files

PathChange+/−
doc/src/sgml/ref/copy.sgml modified +10 −10
src/backend/commands/copyto.c modified +8 −5
src/test/regress/expected/copy.out modified +12 −0
src/test/regress/sql/copy.sql modified +9 −0

Documentation touched

Discussion