COPY TO: provide hint when WHERE clause is used - Mailing list pgsql-hackers

From torikoshia
Subject COPY TO: provide hint when WHERE clause is used
Date
Msg-id 3520c224c5ffac0113aef84a9179f37e@oss.nttdata.com
Whole thread Raw
List pgsql-hackers
Hi,

I saw a user wanted to restrict the rows copied by COPY TO using a WHERE
clause, but ran into an error.

As you know, COPY FROM supports WHERE, but COPY TO does not:

   =# copy t1 to stdout where i > 5;
   ERROR:  WHERE clause not allowed with COPY TO
   LINE 1: copy t1 to stdout where i > 5;
                           ^

In such cases, we can do with specifying a query as the target of COPY:

   =# copy (select i from t1 where i > 5) to stdout;

However, as shown in the first example, no hint is provided in the error
message.

For views or others, COPY TO already provides a helpful hint message:

   =# copy v1 to stdout;
   ERROR:  cannot copy from view "v1"
   HINT:  Try the COPY (SELECT ...) TO variant.

Considering what the user was trying to do, it might be helpful to
provide a similar hint in this case as well.
I’ve attached a patch that adds such a hint.

What do you think?


--
Regards,

--
Atsushi Torikoshi
Seconded from NTT DATA Japan Corporation to SRA OSS K.K.
Attachment

pgsql-hackers by date:

Previous
From: Naga Appani
Date:
Subject: Re: [Proposal] Expose internal MultiXact member count function for efficient monitoring
Next
From: Man Zeng
Date:
Subject: Re: When deleting the plpgsql function, release the CachedPlan of the function