From 8eda8d29e1fdfeaed9fde6f12967416aecfb6449 Mon Sep 17 00:00:00 2001
From: Kyotaro Horiguchi <horiguchi.kyotaro@lab.ntt.co.jp>
Date: Thu, 24 May 2018 21:35:10 +0900
Subject: [PATCH 3/3] Change object description of columns

Previously columns were descripted as "relation R column C", but it
sometimes confusing that it reads as a relation R, not a column
C. This patch transposes the description as "column C of relation R".
---
 src/backend/catalog/objectaddress.c       | 16 +++++++++++++---
 src/test/regress/expected/alter_table.out |  6 +++---
 src/test/regress/expected/collate.out     |  2 +-
 src/test/regress/expected/domain.out      |  8 ++++----
 src/test/regress/expected/sequence.out    |  4 ++--
 src/test/regress/expected/triggers.out    |  8 ++++----
 6 files changed, 27 insertions(+), 17 deletions(-)

diff --git a/src/backend/catalog/objectaddress.c b/src/backend/catalog/objectaddress.c
index 98850df39c..61fe283d74 100644
--- a/src/backend/catalog/objectaddress.c
+++ b/src/backend/catalog/objectaddress.c
@@ -2681,12 +2681,22 @@ getObjectDescription(const ObjectAddress *object)
 	switch (getObjectClass(object))
 	{
 		case OCLASS_CLASS:
-			getRelationDescription(&buffer, object->objectId);
 			if (object->objectSubId != 0)
-				appendStringInfo(&buffer, _(" column %s"),
+			{
+				StringInfoData reldesc;
+
+				initStringInfo(&reldesc);
+				getRelationDescription(&reldesc, object->objectId);
+				appendStringInfo(&buffer, _("column %s of %s"),
 								 get_attname(object->objectId,
 											 object->objectSubId,
-											 false));
+											 false),
+								 reldesc.data);
+				pfree(reldesc.data);
+			}
+			else
+				getRelationDescription(&buffer, object->objectId);
+
 			break;
 
 		case OCLASS_PROC:
diff --git a/src/test/regress/expected/alter_table.out b/src/test/regress/expected/alter_table.out
index 376194c48a..702bf9fe98 100644
--- a/src/test/regress/expected/alter_table.out
+++ b/src/test/regress/expected/alter_table.out
@@ -1844,7 +1844,7 @@ select * from foo;
 (1 row)
 
 drop domain mytype cascade;
-NOTICE:  drop cascades to table foo column f2
+NOTICE:  drop cascades to column f2 of table foo
 select * from foo;
  f1 | f3 
 ----+----
@@ -2870,8 +2870,8 @@ DROP TABLE test_tbl2_subclass;
 CREATE TYPE test_typex AS (a int, b text);
 CREATE TABLE test_tblx (x int, y test_typex check ((y).a > 0));
 ALTER TYPE test_typex DROP ATTRIBUTE a; -- fails
-ERROR:  cannot drop composite type test_typex column a because other objects depend on it
-DETAIL:  constraint test_tblx_y_check on table test_tblx depends on composite type test_typex column a
+ERROR:  cannot drop column a of composite type test_typex because other objects depend on it
+DETAIL:  constraint test_tblx_y_check on table test_tblx depends on column a of composite type test_typex
 HINT:  Use DROP ... CASCADE to drop the dependent objects too.
 ALTER TYPE test_typex DROP ATTRIBUTE a CASCADE;
 NOTICE:  drop cascades to constraint test_tblx_y_check on table test_tblx
diff --git a/src/test/regress/expected/collate.out b/src/test/regress/expected/collate.out
index f045f2b291..fcbe3a5cc8 100644
--- a/src/test/regress/expected/collate.out
+++ b/src/test/regress/expected/collate.out
@@ -631,7 +631,7 @@ DROP COLLATION mycoll1;
 CREATE TABLE collate_test23 (f1 text collate mycoll2);
 DROP COLLATION mycoll2;  -- fail
 ERROR:  cannot drop collation mycoll2 because other objects depend on it
-DETAIL:  table collate_test23 column f1 depends on collation mycoll2
+DETAIL:  column f1 of table collate_test23 depends on collation mycoll2
 HINT:  Use DROP ... CASCADE to drop the dependent objects too.
 -- invalid: non-lowercase quoted identifiers
 CREATE COLLATION case_coll ("Lc_Collate" = "POSIX", "Lc_Ctype" = "POSIX");
diff --git a/src/test/regress/expected/domain.out b/src/test/regress/expected/domain.out
index f4eebb75cf..0b5a9041b0 100644
--- a/src/test/regress/expected/domain.out
+++ b/src/test/regress/expected/domain.out
@@ -298,8 +298,8 @@ ERROR:  operator does not exist: character varying > double precision
 HINT:  No operator matches the given name and argument types. You might need to add explicit type casts.
 alter type comptype alter attribute r type bigint;
 alter type comptype drop attribute r;  -- fail
-ERROR:  cannot drop composite type comptype column r because other objects depend on it
-DETAIL:  constraint c1 depends on composite type comptype column r
+ERROR:  cannot drop column r of composite type comptype because other objects depend on it
+DETAIL:  constraint c1 depends on column r of composite type comptype
 HINT:  Use DROP ... CASCADE to drop the dependent objects too.
 alter type comptype drop attribute i;
 select conname, obj_description(oid, 'pg_constraint') from pg_constraint
@@ -645,8 +645,8 @@ alter domain dnotnulltest drop not null;
 update domnotnull set col1 = null;
 drop domain dnotnulltest cascade;
 NOTICE:  drop cascades to 2 other objects
-DETAIL:  drop cascades to table domnotnull column col1
-drop cascades to table domnotnull column col2
+DETAIL:  drop cascades to column col1 of table domnotnull
+drop cascades to column col2 of table domnotnull
 -- Test ALTER DOMAIN .. DEFAULT ..
 create table domdeftest (col1 ddef1);
 insert into domdeftest default values;
diff --git a/src/test/regress/expected/sequence.out b/src/test/regress/expected/sequence.out
index f2e20a7e85..a0d2b22d3c 100644
--- a/src/test/regress/expected/sequence.out
+++ b/src/test/regress/expected/sequence.out
@@ -293,11 +293,11 @@ CREATE TEMP TABLE t1 (
 -- Both drops should fail, but with different error messages:
 DROP SEQUENCE t1_f1_seq;
 ERROR:  cannot drop sequence t1_f1_seq because other objects depend on it
-DETAIL:  default value for table t1 column f1 depends on sequence t1_f1_seq
+DETAIL:  default value for column f1 of table t1 depends on sequence t1_f1_seq
 HINT:  Use DROP ... CASCADE to drop the dependent objects too.
 DROP SEQUENCE myseq2;
 ERROR:  cannot drop sequence myseq2 because other objects depend on it
-DETAIL:  default value for table t1 column f2 depends on sequence myseq2
+DETAIL:  default value for column f2 of table t1 depends on sequence myseq2
 HINT:  Use DROP ... CASCADE to drop the dependent objects too.
 -- This however will work:
 DROP SEQUENCE myseq3;
diff --git a/src/test/regress/expected/triggers.out b/src/test/regress/expected/triggers.out
index 1f8caef2d7..bf271d536e 100644
--- a/src/test/regress/expected/triggers.out
+++ b/src/test/regress/expected/triggers.out
@@ -557,10 +557,10 @@ LINE 2: FOR EACH STATEMENT WHEN (OLD.* IS DISTINCT FROM NEW.*)
                                  ^
 -- check dependency restrictions
 ALTER TABLE main_table DROP COLUMN b;
-ERROR:  cannot drop table main_table column b because other objects depend on it
-DETAIL:  trigger after_upd_b_row_trig on table main_table depends on table main_table column b
-trigger after_upd_a_b_row_trig on table main_table depends on table main_table column b
-trigger after_upd_b_stmt_trig on table main_table depends on table main_table column b
+ERROR:  cannot drop column b of table main_table because other objects depend on it
+DETAIL:  trigger after_upd_b_row_trig on table main_table depends on column b of table main_table
+trigger after_upd_a_b_row_trig on table main_table depends on column b of table main_table
+trigger after_upd_b_stmt_trig on table main_table depends on column b of table main_table
 HINT:  Use DROP ... CASCADE to drop the dependent objects too.
 -- this should succeed, but we'll roll it back to keep the triggers around
 begin;
-- 
2.16.3

