diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2018-05-24 12:38:55 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2018-05-24 12:38:55 -0400 |
commit | 1a31baf61ed81a13d034bd50db19473ad67acc52 (patch) | |
tree | bd0b9e4d9a972ca58feee23abbbd7388127c7a5e | |
parent | 056f52d9c3ee2dd85b5f1acdbb4e0497f82725b3 (diff) | |
download | postgresql-1a31baf61ed81a13d034bd50db19473ad67acc52.tar.gz postgresql-1a31baf61ed81a13d034bd50db19473ad67acc52.zip |
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
-rw-r--r-- | src/backend/catalog/objectaddress.c | 21 | ||||
-rw-r--r-- | 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 23fc0172b2d..598241110f9 100644 --- a/src/backend/catalog/objectaddress.c +++ b/src/backend/catalog/objectaddress.c @@ -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); + 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 bfd9d54c119..d195a0d7009 100644 --- a/src/test/regress/expected/object_address.out +++ b/src/test/regress/expected/object_address.out @@ -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) --- |