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
This commit is contained in:
Tom Lane 2018-05-24 12:38:55 -04:00
parent 056f52d9c3
commit 1a31baf61e
2 changed files with 14 additions and 9 deletions

View File

@ -3467,6 +3467,7 @@ getObjectDescription(const ObjectAddress *object)
HeapTuple tup;
char *pubname;
Form_pg_publication_rel prform;
StringInfoData rel;
tup = SearchSysCache1(PUBLICATIONREL,
ObjectIdGetDatum(object->objectId));
@ -3477,8 +3478,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;
}
@ -3537,6 +3543,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)
@ -5007,14 +5015,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);
if (objname)
{
getRelationIdentity(&buffer, prform->prrelid, objname);
appendStringInfo(&buffer, " in publication %s", pubname);
if (objargs)
*objargs = list_make1(pubname);
}
ReleaseSysCache(tup);
break;

View File

@ -477,7 +477,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
(47 rows)
---