On Mon, Jan 6, 2025 at 5:34 PM jian he <jian.universal...@gmail.com> wrote: > > hi. > > about this issue, > last email in 2012 (https://postgr.es/m/8967.1353167...@sss.pgh.pa.us) > """ > Even if it happens to be trivial in the current patch, it's an added > functional requirement that we might later regret having cavalierly > signed up for. And, as noted upthread, relations that support only > one direction of COPY don't exist at the moment; that would be adding > an asymmetry that we might later regret, too. > > regards, tom lane > """ > > but now we have numerous COPY options that work solely in a single > direction of COPY. > I think now we can make some kind of relation (pg_class.relkind) that > only works in one direction of COPY.
hi. patch attached. also cc to Tom, since at that time, you are against the idea of ``COPY matview TO``.
From a618e72ae33b6688e75dbcfd5674b558e17ee269 Mon Sep 17 00:00:00 2001 From: jian he <jian.universal...@gmail.com> Date: Tue, 28 Jan 2025 10:46:03 +0800 Subject: [PATCH v1 1/1] COPY materialized_view TO context: https://postgr.es/m/8967.1353167...@sss.pgh.pa.us context: https://www.postgresql.org/message-id/flat/20121116162558.90150%40gmx.com discussion: https://postgr.es/m/CACJufxHVxnyRYy67hiPePNCPwVBMzhTQ6FaL9_Te5On9udG=y...@mail.gmail.com --- src/backend/commands/copyto.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/backend/commands/copyto.c b/src/backend/commands/copyto.c index 99cb23cb34..13506023f8 100644 --- a/src/backend/commands/copyto.c +++ b/src/backend/commands/copyto.c @@ -380,11 +380,13 @@ BeginCopyTo(ParseState *pstate, RelationGetRelationName(rel)), errhint("Try the COPY (SELECT ...) TO variant."))); else if (rel->rd_rel->relkind == RELKIND_MATVIEW) - ereport(ERROR, - (errcode(ERRCODE_WRONG_OBJECT_TYPE), - errmsg("cannot copy from materialized view \"%s\"", - RelationGetRelationName(rel)), - errhint("Try the COPY (SELECT ...) TO variant."))); + { + if (!RelationIsPopulated(rel)) + ereport(ERROR, + errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("cannot copy from materialized view when the materialized view is not populated"), + errhint("Use the REFRESH MATERIALIZED VIEW command populate the materialized view first.")); + } else if (rel->rd_rel->relkind == RELKIND_FOREIGN_TABLE) ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE), -- 2.34.1