Skip to content

Commit 6281f34

Browse files
committed
Back-patch fix to disallow COPY TO/FROM a view (or anything else that's
not a plain relation).
1 parent a11c8be commit 6281f34

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/backend/commands/copy.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.136 2001/03/22 06:16:11 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.136.2.1 2001/08/08 22:32:29 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -305,8 +305,15 @@ DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe,
305305

306306
if (from)
307307
{ /* copy from file to database */
308-
if (rel->rd_rel->relkind == RELKIND_SEQUENCE)
309-
elog(ERROR, "You cannot change sequence relation %s", relname);
308+
if (rel->rd_rel->relkind != RELKIND_RELATION)
309+
{
310+
if (rel->rd_rel->relkind == RELKIND_VIEW)
311+
elog(ERROR, "You cannot copy view %s", relname);
312+
else if (rel->rd_rel->relkind == RELKIND_SEQUENCE)
313+
elog(ERROR, "You cannot change sequence relation %s", relname);
314+
else
315+
elog(ERROR, "You cannot copy object %s", relname);
316+
}
310317
if (pipe)
311318
{
312319
if (IsUnderPostmaster)
@@ -330,6 +337,15 @@ DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe,
330337
}
331338
else
332339
{ /* copy from database to file */
340+
if (rel->rd_rel->relkind != RELKIND_RELATION)
341+
{
342+
if (rel->rd_rel->relkind == RELKIND_VIEW)
343+
elog(ERROR, "You cannot copy view %s", relname);
344+
else if (rel->rd_rel->relkind == RELKIND_SEQUENCE)
345+
elog(ERROR, "You cannot copy sequence %s", relname);
346+
else
347+
elog(ERROR, "You cannot copy object %s", relname);
348+
}
333349
if (pipe)
334350
{
335351
if (IsUnderPostmaster)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy