Back-patch fix to disallow COPY TO/FROM a view (or anything else that's
authorTom Lane <[email protected]>
Wed, 8 Aug 2001 22:32:29 +0000 (22:32 +0000)
committerTom Lane <[email protected]>
Wed, 8 Aug 2001 22:32:29 +0000 (22:32 +0000)
not a plain relation).

src/backend/commands/copy.c

index b47ced1be062507ac6df1d48ae45fad8af705006..bd332531d35caf288d2d132b7ae68af50fc716fa 100644 (file)
@@ -305,8 +305,15 @@ DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe,
 
        if (from)
        {                                                       /* copy from file to database */
-               if (rel->rd_rel->relkind == RELKIND_SEQUENCE)
-                       elog(ERROR, "You cannot change sequence relation %s", relname);
+               if (rel->rd_rel->relkind != RELKIND_RELATION)
+               {
+                       if (rel->rd_rel->relkind == RELKIND_VIEW)
+                               elog(ERROR, "You cannot copy view %s", relname);
+                       else if (rel->rd_rel->relkind == RELKIND_SEQUENCE)
+                               elog(ERROR, "You cannot change sequence relation %s", relname);
+                       else
+                               elog(ERROR, "You cannot copy object %s", relname);
+               }
                if (pipe)
                {
                        if (IsUnderPostmaster)
@@ -330,6 +337,15 @@ DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe,
        }
        else
        {                                                       /* copy from database to file */
+               if (rel->rd_rel->relkind != RELKIND_RELATION)
+               {
+                       if (rel->rd_rel->relkind == RELKIND_VIEW)
+                               elog(ERROR, "You cannot copy view %s", relname);
+                       else if (rel->rd_rel->relkind == RELKIND_SEQUENCE)
+                               elog(ERROR, "You cannot copy sequence %s", relname);
+                       else
+                               elog(ERROR, "You cannot copy object %s", relname);
+               }
                if (pipe)
                {
                        if (IsUnderPostmaster)