]> granicus.if.org Git - postgresql/commitdiff
Fix objectaddress.c code for publication relations.
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 24 May 2018 16:38:55 +0000 (12:38 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 24 May 2018 16:38:55 +0000 (12:38 -0400)
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
src/test/regress/expected/object_address.out

index 23fc0172b2d5b2ae47e75326fcf37a1fe7ca9693..598241110f9fbb31719d721dcd46fcbee8714a86 100644 (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);
+                               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;
index bfd9d54c11939d704ce4e949a483e821ceb0a10b..d195a0d7009e1bac8df782d1da924d8f553c6b59 100644 (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)
 
 ---