From e8cb8fdfd3a219bbc01e80054d58bf6cbce745ef Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Thu, 24 May 2018 12:38:55 -0400 Subject: [PATCH] Fix objectaddress.c code for publication relations. getObjectDescription and getObjectIdentity failed to schema-qualify the name of the published table, which is bad in getObjectDescription and unforgivable in getObjectIdentity. Actually, getObjectIdentity failed to emit the table's name at all unless "objname" output is requested, which accidentally works for some (all?) extant callers but is clearly not the intended API. Somebody had also not gotten the memo that the output of getObjectIdentity is not to be translated. To fix getObjectDescription, I made it call getRelationDescription, which required refactoring the translatable string for the case, but is more future-proof in case we ever publish relations that aren't plain tables. While at it, I made the English output look like "publication of table X in publication Y"; the added "of" seems to me to make it read much better. Back-patch to v10 where publications were introduced. Discussion: https://postgr.es/m/20180522.182020.114074746.horiguchi.kyotaro@lab.ntt.co.jp --- src/backend/catalog/objectaddress.c | 21 ++++++++++++-------- src/test/regress/expected/object_address.out | 2 +- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/backend/catalog/objectaddress.c b/src/backend/catalog/objectaddress.c index 270c685333..88e69f70fc 100644 --- a/src/backend/catalog/objectaddress.c +++ b/src/backend/catalog/objectaddress.c @@ -3446,6 +3446,7 @@ getObjectDescription(const ObjectAddress *object) HeapTuple tup; char *pubname; Form_pg_publication_rel prform; + StringInfoData rel; tup = SearchSysCache1(PUBLICATIONREL, ObjectIdGetDatum(object->objectId)); @@ -3456,8 +3457,13 @@ getObjectDescription(const ObjectAddress *object) prform = (Form_pg_publication_rel) GETSTRUCT(tup); pubname = get_publication_name(prform->prpubid); - appendStringInfo(&buffer, _("publication table %s in publication %s"), - get_rel_name(prform->prrelid), pubname); + initStringInfo(&rel); + getRelationDescription(&rel, prform->prrelid); + + /* translator: first %s is, e.g., "table %s" */ + appendStringInfo(&buffer, _("publication of %s in publication %s"), + rel.data, pubname); + pfree(rel.data); ReleaseSysCache(tup); break; } @@ -3516,6 +3522,8 @@ getObjectDescriptionOids(Oid classid, Oid objid) /* * subroutine for getObjectDescription: describe a relation + * + * The result is appended to "buffer". */ static void getRelationDescription(StringInfo buffer, Oid relid) @@ -4982,14 +4990,11 @@ getObjectIdentityParts(const ObjectAddress *object, prform = (Form_pg_publication_rel) GETSTRUCT(tup); pubname = get_publication_name(prform->prpubid); - appendStringInfo(&buffer, _("%s in publication %s"), - get_rel_name(prform->prrelid), pubname); + getRelationIdentity(&buffer, prform->prrelid, objname); + appendStringInfo(&buffer, " in publication %s", pubname); - if (objname) - { - getRelationIdentity(&buffer, prform->prrelid, objname); + if (objargs) *objargs = list_make1(pubname); - } ReleaseSysCache(tup); break; diff --git a/src/test/regress/expected/object_address.out b/src/test/regress/expected/object_address.out index 1fdadbc9ef..d12bf01877 100644 --- a/src/test/regress/expected/object_address.out +++ b/src/test/regress/expected/object_address.out @@ -468,7 +468,7 @@ SELECT (pg_identify_object(addr1.classid, addr1.objid, addr1.objsubid)).*, text search template | addr_nsp | addr_ts_temp | addr_nsp.addr_ts_temp | t subscription | | addr_sub | addr_sub | t publication | | addr_pub | addr_pub | t - publication relation | | | gentable in publication addr_pub | t + publication relation | | | addr_nsp.gentable in publication addr_pub | t (46 rows) --- -- 2.40.0