I found the following while poking around. RangeVarGetRelid takes a
second parameter that is intended to allow it to not fail, returning
InvalidOid instead. However it calls LookupExplicitNamespace, which does
not honor any such request, and happily generates an error on a bad
namespace name:
/* * RangeVarGetRelid * Given a RangeVar describing an existing relation, * select the proper namespace and
lookup the relation OID. * * If the relation is not found, return InvalidOid if failOK = true, * otherwise raise an
error.*/
Oid
RangeVarGetRelid(const RangeVar *relation, bool failOK)
{
[...] if (relation->schemaname) { /* use exact schema given */ namespaceId =
LookupExplicitNamespace(relation->schemaname); relId = get_relname_relid(relation->relname, namespaceId); }
[...]
}
Oid
LookupExplicitNamespace(const char *nspname)
{
[...] namespaceId = GetSysCacheOid(NAMESPACENAME, CStringGetDatum(nspname),0, 0, 0); if
(!OidIsValid(namespaceId)) elog(ERROR, "Namespace \"%s\" does not exist", nspname);
[...]
}
Shouldn't LookupExplicitNamespace be changed to allow the same second
parameter? All uses of LookupExplicitNamespace, besides in
RangeVarGetRelid, would have the parameter set to false.
Comments?
Joe