Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfec1ad9

Browse files
committed
Include typmod when complaining about inherited column type mismatches.
MergeAttributes() rejects cases where columns to be merged have the sametype but different typmod, which is correct; but the error message itprinted didn't show either typmod, which is unhelpful. Changing thisrequires using format_type_with_typemod() in place of TypeNameToString(),which will have some minor side effects on the way some type names areprinted, but on balance this is an improvement: the old code sometimesprinted one type according to one set of rules and the other type accordingto 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
1 parent3d2b31e commitfec1ad9

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

‎src/backend/commands/tablecmds.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,8 +1613,10 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
16131613
errmsg("inherited column \"%s\" has a type conflict",
16141614
attributeName),
16151615
errdetail("%s versus %s",
1616-
TypeNameToString(def->typeName),
1617-
format_type_be(attribute->atttypid))));
1616+
format_type_with_typemod(defTypeId,
1617+
deftypmod),
1618+
format_type_with_typemod(attribute->atttypid,
1619+
attribute->atttypmod))));
16181620
defCollId=GetColumnDefCollation(NULL,def,defTypeId);
16191621
if (defCollId!=attribute->attcollation)
16201622
ereport(ERROR,
@@ -1832,8 +1834,10 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
18321834
errmsg("column \"%s\" has a type conflict",
18331835
attributeName),
18341836
errdetail("%s versus %s",
1835-
TypeNameToString(def->typeName),
1836-
TypeNameToString(newdef->typeName))));
1837+
format_type_with_typemod(defTypeId,
1838+
deftypmod),
1839+
format_type_with_typemod(newTypeId,
1840+
newtypmod))));
18371841
defcollid=GetColumnDefCollation(NULL,def,defTypeId);
18381842
newcollid=GetColumnDefCollation(NULL,newdef,newTypeId);
18391843
if (defcollid!=newcollid)

‎src/test/regress/expected/alter_table.out

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,6 +1268,27 @@ select * from child;
12681268
12 | testing
12691269
(1 row)
12701270

1271+
drop table child;
1272+
drop table parent;
1273+
-- check error cases for inheritance column merging
1274+
create table parent (a float8, b numeric(10,4), c text collate "C");
1275+
create table child (a float4) inherits (parent); -- fail
1276+
NOTICE: merging column "a" with inherited definition
1277+
ERROR: column "a" has a type conflict
1278+
DETAIL: double precision versus real
1279+
create table child (b decimal(10,7)) inherits (parent); -- fail
1280+
NOTICE: moving and merging column "b" with inherited definition
1281+
DETAIL: User-specified column moved to the position of the inherited column.
1282+
ERROR: column "b" has a type conflict
1283+
DETAIL: numeric(10,4) versus numeric(10,7)
1284+
create table child (c text collate "POSIX") inherits (parent); -- fail
1285+
NOTICE: moving and merging column "c" with inherited definition
1286+
DETAIL: User-specified column moved to the position of the inherited column.
1287+
ERROR: column "c" has a collation conflict
1288+
DETAIL: "C" versus "POSIX"
1289+
create table child (a double precision, b decimal(10,4)) inherits (parent);
1290+
NOTICE: merging column "a" with inherited definition
1291+
NOTICE: merging column "b" with inherited definition
12711292
drop table child;
12721293
drop table parent;
12731294
-- test copy in/out

‎src/test/regress/sql/alter_table.sql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,17 @@ select * from child;
906906
droptable child;
907907
droptable parent;
908908

909+
-- check error cases for inheritance column merging
910+
createtableparent (a float8, bnumeric(10,4), ctext collate"C");
911+
912+
createtablechild (a float4) inherits (parent);-- fail
913+
createtablechild (bdecimal(10,7)) inherits (parent);-- fail
914+
createtablechild (ctext collate"POSIX") inherits (parent);-- fail
915+
createtablechild (adouble precision, bdecimal(10,4)) inherits (parent);
916+
917+
droptable child;
918+
droptable parent;
919+
909920
-- test copy in/out
910921
createtabletest (a int4, b int4, c int4);
911922
insert into testvalues (1,2,3);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp