diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2015-12-26 13:41:29 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2015-12-26 13:41:29 -0500 |
commit | fec1ad94dfc5ddacfda8d249bf4b3c739da8f7a1 (patch) | |
tree | 8194e0fe4c1c00d7cf0a5869747c82334df9898f /src | |
parent | 3d2b31e30e2931b3edb5ab9d0eafca13e7bcffe5 (diff) | |
download | postgresql-fec1ad94dfc5ddacfda8d249bf4b3c739da8f7a1.tar.gz postgresql-fec1ad94dfc5ddacfda8d249bf4b3c739da8f7a1.zip |
Include typmod when complaining about inherited column type mismatches.
MergeAttributes() rejects cases where columns to be merged have the same
type but different typmod, which is correct; but the error message it
printed didn't show either typmod, which is unhelpful. Changing this
requires using format_type_with_typemod() in place of TypeNameToString(),
which will have some minor side effects on the way some type names are
printed, but on balance this is an improvement: the old code sometimes
printed one type according to one set of rules and the other type according
to the other set, which could be confusing in its own way.
Oddly, there were no regression test cases covering any of this behavior,
so add some.
Complaint and fix by Amit Langote
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/commands/tablecmds.c | 12 | ||||
-rw-r--r-- | src/test/regress/expected/alter_table.out | 21 | ||||
-rw-r--r-- | src/test/regress/sql/alter_table.sql | 11 |
3 files changed, 40 insertions, 4 deletions
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 56fed4d87cd..a217dbcb1ef 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -1613,8 +1613,10 @@ MergeAttributes(List *schema, List *supers, char relpersistence, errmsg("inherited column \"%s\" has a type conflict", attributeName), errdetail("%s versus %s", - TypeNameToString(def->typeName), - format_type_be(attribute->atttypid)))); + format_type_with_typemod(defTypeId, + deftypmod), + format_type_with_typemod(attribute->atttypid, + attribute->atttypmod)))); defCollId = GetColumnDefCollation(NULL, def, defTypeId); if (defCollId != attribute->attcollation) ereport(ERROR, @@ -1832,8 +1834,10 @@ MergeAttributes(List *schema, List *supers, char relpersistence, errmsg("column \"%s\" has a type conflict", attributeName), errdetail("%s versus %s", - TypeNameToString(def->typeName), - TypeNameToString(newdef->typeName)))); + format_type_with_typemod(defTypeId, + deftypmod), + format_type_with_typemod(newTypeId, + newtypmod)))); defcollid = GetColumnDefCollation(NULL, def, defTypeId); newcollid = GetColumnDefCollation(NULL, newdef, newTypeId); if (defcollid != newcollid) diff --git a/src/test/regress/expected/alter_table.out b/src/test/regress/expected/alter_table.out index 228ae6ec221..7c88ddc9fed 100644 --- a/src/test/regress/expected/alter_table.out +++ b/src/test/regress/expected/alter_table.out @@ -1270,6 +1270,27 @@ select * from child; drop table child; drop table parent; +-- check error cases for inheritance column merging +create table parent (a float8, b numeric(10,4), c text collate "C"); +create table child (a float4) inherits (parent); -- fail +NOTICE: merging column "a" with inherited definition +ERROR: column "a" has a type conflict +DETAIL: double precision versus real +create table child (b decimal(10,7)) inherits (parent); -- fail +NOTICE: moving and merging column "b" with inherited definition +DETAIL: User-specified column moved to the position of the inherited column. +ERROR: column "b" has a type conflict +DETAIL: numeric(10,4) versus numeric(10,7) +create table child (c text collate "POSIX") inherits (parent); -- fail +NOTICE: moving and merging column "c" with inherited definition +DETAIL: User-specified column moved to the position of the inherited column. +ERROR: column "c" has a collation conflict +DETAIL: "C" versus "POSIX" +create table child (a double precision, b decimal(10,4)) inherits (parent); +NOTICE: merging column "a" with inherited definition +NOTICE: merging column "b" with inherited definition +drop table child; +drop table parent; -- test copy in/out create table test (a int4, b int4, c int4); insert into test values (1,2,3); diff --git a/src/test/regress/sql/alter_table.sql b/src/test/regress/sql/alter_table.sql index 3db34609733..72e65d4ee05 100644 --- a/src/test/regress/sql/alter_table.sql +++ b/src/test/regress/sql/alter_table.sql @@ -906,6 +906,17 @@ select * from child; drop table child; drop table parent; +-- check error cases for inheritance column merging +create table parent (a float8, b numeric(10,4), c text collate "C"); + +create table child (a float4) inherits (parent); -- fail +create table child (b decimal(10,7)) inherits (parent); -- fail +create table child (c text collate "POSIX") inherits (parent); -- fail +create table child (a double precision, b decimal(10,4)) inherits (parent); + +drop table child; +drop table parent; + -- test copy in/out create table test (a int4, b int4, c int4); insert into test values (1,2,3); |