Clarify error message when attempting to create index on foreign table
authorMagnus Hagander <magnus@hagander.net>
Thu, 5 May 2011 19:47:42 +0000 (21:47 +0200)
committerMagnus Hagander <magnus@hagander.net>
Thu, 5 May 2011 19:47:42 +0000 (21:47 +0200)
Instead of just saying "is not a table", specifically state that
indexes aren't supported on *foreign* tables.

src/backend/commands/indexcmds.c

index ff84045d4fc4d69e42c0bb8cc367eae1e2927753..b91e4a4bd2b99fa782fa92aab9afd9e35c373488 100644 (file)
@@ -183,10 +183,22 @@ DefineIndex(RangeVar *heapRelation,
    /* Note: during bootstrap may see uncataloged relation */
    if (rel->rd_rel->relkind != RELKIND_RELATION &&
        rel->rd_rel->relkind != RELKIND_UNCATALOGED)
-       ereport(ERROR,
-               (errcode(ERRCODE_WRONG_OBJECT_TYPE),
-                errmsg("\"%s\" is not a table",
-                       heapRelation->relname)));
+   {
+       if (rel->rd_rel->relkind == RELKIND_FOREIGN_TABLE)
+           /*
+            * Custom error message for FOREIGN TABLE since the term is
+            * close to a regular table and can confuse the user.
+            */
+           ereport(ERROR,
+                   (errcode(ERRCODE_WRONG_OBJECT_TYPE),
+                    errmsg("cannot create index on foreign table \"%s\"",
+                        heapRelation->relname)));
+       else
+           ereport(ERROR,
+                   (errcode(ERRCODE_WRONG_OBJECT_TYPE),
+                    errmsg("\"%s\" is not a table",
+                           heapRelation->relname)));
+   }
 
    /*
     * Don't try to CREATE INDEX on temp tables of other backends.