@@ -149,6 +149,28 @@ is_publishable_relation(Relation rel)
149149 return is_publishable_class (RelationGetRelid (rel ), rel -> rd_rel );
150150}
151151
152+ /*
153+ * SQL-callable variant of the above
154+ *
155+ * This returns null when the relation does not exist. This is intended to be
156+ * used for example in psql to avoid gratuitous errors when there are
157+ * concurrent catalog changes.
158+ */
159+ Datum
160+ pg_relation_is_publishable (PG_FUNCTION_ARGS )
161+ {
162+ Oid relid = PG_GETARG_OID (0 );
163+ HeapTuple tuple ;
164+ bool result ;
165+
166+ tuple = SearchSysCache1 (RELOID , ObjectIdGetDatum (relid ));
167+ if (!HeapTupleIsValid (tuple ))
168+ PG_RETURN_NULL ();
169+ result = is_publishable_class (relid , (Form_pg_class ) GETSTRUCT (tuple ));
170+ ReleaseSysCache (tuple );
171+ PG_RETURN_BOOL (result );
172+ }
173+
152174/*
153175 * Filter out the partitions whose parent tables were also specified in
154176 * the publication.
@@ -219,28 +241,6 @@ is_schema_publication(Oid pubid)
219241 return result ;
220242}
221243
222- /*
223- * SQL-callable variant of the above
224- *
225- * This returns null when the relation does not exist. This is intended to be
226- * used for example in psql to avoid gratuitous errors when there are
227- * concurrent catalog changes.
228- */
229- Datum
230- pg_relation_is_publishable (PG_FUNCTION_ARGS )
231- {
232- Oid relid = PG_GETARG_OID (0 );
233- HeapTuple tuple ;
234- bool result ;
235-
236- tuple = SearchSysCache1 (RELOID , ObjectIdGetDatum (relid ));
237- if (!HeapTupleIsValid (tuple ))
238- PG_RETURN_NULL ();
239- result = is_publishable_class (relid , (Form_pg_class ) GETSTRUCT (tuple ));
240- ReleaseSysCache (tuple );
241- PG_RETURN_BOOL (result );
242- }
243-
244244/*
245245 * Gets the relations based on the publication partition option for a specified
246246 * relation.
@@ -1012,7 +1012,6 @@ GetPublication(Oid pubid)
10121012 return pub ;
10131013}
10141014
1015-
10161015/*
10171016 * Get Publication using name.
10181017 */
@@ -1026,56 +1025,6 @@ GetPublicationByName(const char *pubname, bool missing_ok)
10261025 return OidIsValid (oid ) ? GetPublication (oid ) : NULL ;
10271026}
10281027
1029- /*
1030- * get_publication_oid - given a publication name, look up the OID
1031- *
1032- * If missing_ok is false, throw an error if name not found. If true, just
1033- * return InvalidOid.
1034- */
1035- Oid
1036- get_publication_oid (const char * pubname , bool missing_ok )
1037- {
1038- Oid oid ;
1039-
1040- oid = GetSysCacheOid1 (PUBLICATIONNAME , Anum_pg_publication_oid ,
1041- CStringGetDatum (pubname ));
1042- if (!OidIsValid (oid ) && !missing_ok )
1043- ereport (ERROR ,
1044- (errcode (ERRCODE_UNDEFINED_OBJECT ),
1045- errmsg ("publication \"%s\" does not exist" , pubname )));
1046- return oid ;
1047- }
1048-
1049- /*
1050- * get_publication_name - given a publication Oid, look up the name
1051- *
1052- * If missing_ok is false, throw an error if name not found. If true, just
1053- * return NULL.
1054- */
1055- char *
1056- get_publication_name (Oid pubid , bool missing_ok )
1057- {
1058- HeapTuple tup ;
1059- char * pubname ;
1060- Form_pg_publication pubform ;
1061-
1062- tup = SearchSysCache1 (PUBLICATIONOID , ObjectIdGetDatum (pubid ));
1063-
1064- if (!HeapTupleIsValid (tup ))
1065- {
1066- if (!missing_ok )
1067- elog (ERROR , "cache lookup failed for publication %u" , pubid );
1068- return NULL ;
1069- }
1070-
1071- pubform = (Form_pg_publication ) GETSTRUCT (tup );
1072- pubname = pstrdup (NameStr (pubform -> pubname ));
1073-
1074- ReleaseSysCache (tup );
1075-
1076- return pubname ;
1077- }
1078-
10791028/*
10801029 * Returns information of tables in a publication.
10811030 */
0 commit comments