Issue clearer notice when inherited merged columns are moved
authorBruce Momjian <[email protected]>
Wed, 3 Sep 2014 15:54:31 +0000 (11:54 -0400)
committerBruce Momjian <[email protected]>
Wed, 3 Sep 2014 15:54:31 +0000 (11:54 -0400)
CREATE TABLE INHERIT moves user-specified columns to the location of the
inherited column.

Report by Fatal Majid

src/backend/commands/tablecmds.c

index 3720a0fe56300bcab1442e672c31fee1f725c34e..0a679be24e7d5c4d2502b3b5831cb2420d194b20 100644 (file)
@@ -1756,12 +1756,16 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
         */
        if (inhSchema != NIL)
        {
+               int             schema_attno = 0;
+
                foreach(entry, schema)
                {
                        ColumnDef  *newdef = lfirst(entry);
                        char       *attributeName = newdef->colname;
                        int                     exist_attno;
 
+                       schema_attno++;
+
                        /*
                         * Does it conflict with some previously inherited column?
                         */
@@ -1780,9 +1784,14 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
                                 * Yes, try to merge the two column definitions. They must
                                 * have the same type, typmod, and collation.
                                 */
-                               ereport(NOTICE,
-                                  (errmsg("merging column \"%s\" with inherited definition",
-                                                  attributeName)));
+                                if (exist_attno == schema_attno)
+                                       ereport(NOTICE,
+                                          (errmsg("merging column \"%s\" with inherited definition",
+                                                          attributeName)));
+                               else
+                                       ereport(NOTICE,
+                                          (errmsg("moving and merging column \"%s\" with inherited definition", attributeName),
+                                               errdetail("User-specified column moved to the position of the inherited column.")));
                                def = (ColumnDef *) list_nth(inhSchema, exist_attno - 1);
                                typenameTypeIdAndMod(NULL, def->typeName, &defTypeId, &deftypmod);
                                typenameTypeIdAndMod(NULL, newdef->typeName, &newTypeId, &newtypmod);