]> 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 270c685333529c1fe333d6e78195d5ab9c93e409..88e69f70fc19e6c7be52b1e0c85b1f03537b9fb2 100644 (file)
@@ -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;
index 1fdadbc9ef6324716012ac25425d5db3543a96aa..d12bf018771c85f0fac10586beffb5ed7a5aca24 100644 (file)
@@ -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)
 
 ---