Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tzYBo-003UVs-BU for pgsql-hackers@arkaria.postgresql.org; Tue, 01 Apr 2025 09:45:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tzYBk-000GlA-SN for pgsql-hackers@arkaria.postgresql.org; Tue, 01 Apr 2025 09:45:44 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tzYBk-000Gl2-Iv for pgsql-hackers@lists.postgresql.org; Tue, 01 Apr 2025 09:45:44 +0000 Received: from mail-yw1-x112c.google.com ([2607:f8b0:4864:20::112c]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tzYBi-002jAQ-1l for pgsql-hackers@postgresql.org; Tue, 01 Apr 2025 09:45:44 +0000 Received: by mail-yw1-x112c.google.com with SMTP id 00721157ae682-6fed0620395so49064187b3.3 for ; Tue, 01 Apr 2025 02:45:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1743500741; x=1744105541; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=mIMBYbAJzJC75Byx/O1sWtlSUdEyhxqFNDYbPVDH4WM=; b=TG3dCUlS04DE5UsZNN87KaK/S7CErq/0B0YmTfh7RKS2JX2cUeZp5F10DdoYB/2RV7 IeoBVulQzCbpGdDknXw1g1PqiiCVtEkRUoGrzZqjgoeR+OpAl+XCalBneoFH1s68Lzmq FNkn0cIc7xhuJnmeNjODANNYi9z5mMuYLEKRv8Wd0sDITYhJlxmdfp4ne+JtqojpuDkh IH7fXmkHyXanE3uWWPwhkMY5zvF6GJkDiTvTg4LM+9r+rctlzWKPfW1YQbsi2JHEjh73 ezcjuQ01On4U0jendByXqIpHjRTvxNL7pxH5ao4V1QGssdFNFyofVvTr3l60pLeDlFQw +cBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743500741; x=1744105541; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mIMBYbAJzJC75Byx/O1sWtlSUdEyhxqFNDYbPVDH4WM=; b=UEvySw8JWytoVVKTZe7as1ctUJ7vpsFfNhg373i32BpmACLCamismJbgYd/rm3TRDc LI76BT3WmsZ5Qg/mwfpyHkoh+zpF5xT+s7RlYQDUg9CuvCod7t7Kp1tlHvQoNpSGCQgh z8UpwXOsvLzIs3Oh8Q+wq3r1kgfpF3tvKE2bIkIb7WksYlQIlxgyKSttmXpG6v4CjJ2+ 4XMr7abaeYLOiympMYuguXfQ/URMuyi2aJ1k7YI/YPT2QRn4TNf1tzoFHD0T6G2gxPg7 SvrGkaRmvCcxOP/p0VyZfj2L6PZDweRsMCEnBW4qrUGYBOv0ATK5d1jg2K8DdaYVUAT0 wMRw== X-Forwarded-Encrypted: i=1; AJvYcCV46PdG/ng6qTDLIwnUGNzCKMpr8+NA1qo33CuNSOXDtls9ecaT9ZiuPrQeZBUf0JOY8hXmgojTSBus8/dE@postgresql.org X-Gm-Message-State: AOJu0YzI+84aXuzOHWwuWgzkAB4vwon75rcBIlPf6lVH2BhMKpQ8hcnO QqWub9X//UqfkjeLgE58wOGy3pqI585vkJ0YVUNIYp88x8xlV5rKVtJAowZBcWWPf3iiVZ6gwvO NFBtLnhJQ20y9fnHWMZRPEY7v2/GHPNT+bro= X-Gm-Gg: ASbGncsuT9T0lT0RKemazoXjnfwHEmHrlcGBAXggYqGZo2sv3N6htw8uEV8Mhnb+2W+ 6cHEsS4UQ3GPY9ChxwgLfMjHtFwkMCA0te6vLpm10HPvEZPl/wOAGDaEj8+NybYIZBpa8bWF32j D1JmqdBS9TOyp4OUkxH1dw23hamP1R X-Google-Smtp-Source: AGHT+IF3uundCcsW+r6aazxPB1jYCEtkeXvfy14M0DUVWBJn1JHtJ/oa2HJlmN+RIAZby9ibKwEnb4muxpf5MxMp2wo= X-Received: by 2002:a81:fb0d:0:b0:703:ac44:d367 with SMTP id 00721157ae682-703ac44fa89mr8416247b3.6.1743500740759; Tue, 01 Apr 2025 02:45:40 -0700 (PDT) MIME-Version: 1.0 References: <442e62f7-ef64-4df1-8453-d682fe9bdaa3@dunslane.net> <425ebe4b-06c5-4212-af68-fd0e5537c250@dunslane.net> In-Reply-To: From: vignesh C Date: Tue, 1 Apr 2025 15:15:28 +0530 X-Gm-Features: AQ5f1JpgH3-I7I3kZCerkdNsETnKQl4WYo24XzSsvCYbjSRfZCYhSvioHVoM3LE Message-ID: Subject: Re: in BeginCopyTo make materialized view using COPY TO instead of COPY (query). To: jian he Cc: Fujii Masao , Andrew Dunstan , "David G. Johnston" , Kirill Reshke , PostgreSQL-development , Tom Lane , Michael Paquier Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, 1 Apr 2025 at 08:43, jian he wrote: > > On Mon, Mar 31, 2025 at 11:27=E2=80=AFPM Fujii Masao > wrote: > > > > Regarding the patch, here are some review comments: > > > > + errmsg("cannot copy fro= m materialized view when the materialized view is not populated"), > > > > How about including the object name for consistency with > > other error messages in BeginCopyTo(), like this? > > > > errmsg("cannot copy from unpopulated materialized view \"%s\"", > > RelationGetRelationName(rel)), > > > > > > + errhint("Use the REFRES= H MATERIALIZED VIEW command populate the materialized view first.")); > > > > There seems to be a missing "to" just after "command". > > Should it be "Use the REFRESH MATERIALIZED VIEW command to > > populate the materialized view first."? Or we could simplify > > the hint to match what SELECT on an unpopulated materialized > > view logs: "Use the REFRESH MATERIALIZED VIEW command.". > > > based on your suggestion, i changed it to: > > if (!RelationIsPopulated(rel)) > ereport(ERROR, > errcode(ERRCODE_FEATURE_NOT_SUPPORTED), > errmsg("cannot copy from unpopulated > materialized view \"%s\"", > RelationGetRelationName(rel)), > errhint("Use the REFRESH MATERIALIZED VIEW > command to populate the materialized view first.")); > > > > > > The copy.sgml documentation should clarify that COPY TO can > > be used with a materialized view only if it is populated. > > > "COPY TO can be used only with plain tables, not views, and does not > copy rows from child tables or child partitions" > i changed it to > "COPY TO can be used with plain tables and materialized views, not > regular views, and does not copy rows from child tables or child > partitions" > > Another alternative wording I came up with: > "COPY TO can only be used with plain tables and materialized views, > not regular views. It also does not copy rows from child tables or > child partitions." One thing I noticed was that if the materialized view is not refreshed user will get stale data: postgres=3D# create table t1(c1 int); CREATE TABLE postgres=3D# create materialized view mv2 as select * from t1; SELECT 0 postgres=3D# insert into t1 values(10); INSERT 0 1 postgres=3D# select * from t1; c1 ---- 10 (1 row) -- Before refresh the data will not be selected postgres=3D# copy mv2 to stdout with (header); c1 -- After refresh the data will be available postgres=3D# refresh materialized view mv2; REFRESH MATERIALIZED VIEW postgres=3D# copy mv2 to stdout with (header); c1 10 Should we document this? The following can be changed to keep it consistent: +copy matview1(id) TO stdout with (header); +copy matview2 TO stdout with (header); To: COPY matview1(id) TO stdout with (header); COPY matview2 TO stdout with (header); Regards, Vignesh