@@ -291,7 +291,11 @@ RangeVarGetRelidExtended(const RangeVar *relation, LOCKMODE lockmode,
291
291
{
292
292
Oid namespaceId ;
293
293
294
- namespaceId = LookupExplicitNamespace (relation -> schemaname );
294
+ namespaceId = LookupExplicitNamespace (relation -> schemaname , missing_ok );
295
+ /*
296
+ * For missing_ok, allow a non-existant schema name
297
+ * to throw the error below (namespaceId == InvalidOid).
298
+ */
295
299
if (namespaceId != myTempNamespace )
296
300
ereport (ERROR ,
297
301
(errcode (ERRCODE_INVALID_TABLE_DEFINITION ),
@@ -306,8 +310,11 @@ RangeVarGetRelidExtended(const RangeVar *relation, LOCKMODE lockmode,
306
310
Oid namespaceId ;
307
311
308
312
/* use exact schema given */
309
- namespaceId = LookupExplicitNamespace (relation -> schemaname );
310
- relId = get_relname_relid (relation -> relname , namespaceId );
313
+ namespaceId = LookupExplicitNamespace (relation -> schemaname , missing_ok );
314
+ if (missing_ok && !OidIsValid (namespaceId ))
315
+ relId = InvalidOid ;
316
+ else
317
+ relId = get_relname_relid (relation -> relname , namespaceId );
311
318
}
312
319
else
313
320
{
@@ -919,7 +926,7 @@ FuncnameGetCandidates(List *names, int nargs, List *argnames,
919
926
if (schemaname )
920
927
{
921
928
/* use exact schema given */
922
- namespaceId = LookupExplicitNamespace (schemaname );
929
+ namespaceId = LookupExplicitNamespace (schemaname , false );
923
930
}
924
931
else
925
932
{
@@ -1453,7 +1460,7 @@ OpernameGetOprid(List *names, Oid oprleft, Oid oprright)
1453
1460
Oid namespaceId ;
1454
1461
HeapTuple opertup ;
1455
1462
1456
- namespaceId = LookupExplicitNamespace (schemaname );
1463
+ namespaceId = LookupExplicitNamespace (schemaname , false );
1457
1464
opertup = SearchSysCache4 (OPERNAMENSP ,
1458
1465
CStringGetDatum (opername ),
1459
1466
ObjectIdGetDatum (oprleft ),
@@ -1551,7 +1558,7 @@ OpernameGetCandidates(List *names, char oprkind)
1551
1558
if (schemaname )
1552
1559
{
1553
1560
/* use exact schema given */
1554
- namespaceId = LookupExplicitNamespace (schemaname );
1561
+ namespaceId = LookupExplicitNamespace (schemaname , false );
1555
1562
}
1556
1563
else
1557
1564
{
@@ -2093,10 +2100,13 @@ get_ts_parser_oid(List *names, bool missing_ok)
2093
2100
if (schemaname )
2094
2101
{
2095
2102
/* use exact schema given */
2096
- namespaceId = LookupExplicitNamespace (schemaname );
2097
- prsoid = GetSysCacheOid2 (TSPARSERNAMENSP ,
2098
- PointerGetDatum (parser_name ),
2099
- ObjectIdGetDatum (namespaceId ));
2103
+ namespaceId = LookupExplicitNamespace (schemaname , missing_ok );
2104
+ if (missing_ok && !OidIsValid (namespaceId ))
2105
+ prsoid = InvalidOid ;
2106
+ else
2107
+ prsoid = GetSysCacheOid2 (TSPARSERNAMENSP ,
2108
+ PointerGetDatum (parser_name ),
2109
+ ObjectIdGetDatum (namespaceId ));
2100
2110
}
2101
2111
else
2102
2112
{
@@ -2216,10 +2226,13 @@ get_ts_dict_oid(List *names, bool missing_ok)
2216
2226
if (schemaname )
2217
2227
{
2218
2228
/* use exact schema given */
2219
- namespaceId = LookupExplicitNamespace (schemaname );
2220
- dictoid = GetSysCacheOid2 (TSDICTNAMENSP ,
2221
- PointerGetDatum (dict_name ),
2222
- ObjectIdGetDatum (namespaceId ));
2229
+ namespaceId = LookupExplicitNamespace (schemaname , missing_ok );
2230
+ if (missing_ok && !OidIsValid (namespaceId ))
2231
+ dictoid = InvalidOid ;
2232
+ else
2233
+ dictoid = GetSysCacheOid2 (TSDICTNAMENSP ,
2234
+ PointerGetDatum (dict_name ),
2235
+ ObjectIdGetDatum (namespaceId ));
2223
2236
}
2224
2237
else
2225
2238
{
@@ -2340,10 +2353,13 @@ get_ts_template_oid(List *names, bool missing_ok)
2340
2353
if (schemaname )
2341
2354
{
2342
2355
/* use exact schema given */
2343
- namespaceId = LookupExplicitNamespace (schemaname );
2344
- tmploid = GetSysCacheOid2 (TSTEMPLATENAMENSP ,
2345
- PointerGetDatum (template_name ),
2346
- ObjectIdGetDatum (namespaceId ));
2356
+ namespaceId = LookupExplicitNamespace (schemaname , missing_ok );
2357
+ if (missing_ok && !OidIsValid (namespaceId ))
2358
+ tmploid = InvalidOid ;
2359
+ else
2360
+ tmploid = GetSysCacheOid2 (TSTEMPLATENAMENSP ,
2361
+ PointerGetDatum (template_name ),
2362
+ ObjectIdGetDatum (namespaceId ));
2347
2363
}
2348
2364
else
2349
2365
{
@@ -2463,10 +2479,13 @@ get_ts_config_oid(List *names, bool missing_ok)
2463
2479
if (schemaname )
2464
2480
{
2465
2481
/* use exact schema given */
2466
- namespaceId = LookupExplicitNamespace (schemaname );
2467
- cfgoid = GetSysCacheOid2 (TSCONFIGNAMENSP ,
2468
- PointerGetDatum (config_name ),
2469
- ObjectIdGetDatum (namespaceId ));
2482
+ namespaceId = LookupExplicitNamespace (schemaname , missing_ok );
2483
+ if (missing_ok && !OidIsValid (namespaceId ))
2484
+ cfgoid = InvalidOid ;
2485
+ else
2486
+ cfgoid = GetSysCacheOid2 (TSCONFIGNAMENSP ,
2487
+ PointerGetDatum (config_name ),
2488
+ ObjectIdGetDatum (namespaceId ));
2470
2489
}
2471
2490
else
2472
2491
{
@@ -2657,7 +2676,7 @@ LookupNamespaceNoError(const char *nspname)
2657
2676
* Returns the namespace OID. Raises ereport if any problem.
2658
2677
*/
2659
2678
Oid
2660
- LookupExplicitNamespace (const char * nspname )
2679
+ LookupExplicitNamespace (const char * nspname , bool missing_ok )
2661
2680
{
2662
2681
Oid namespaceId ;
2663
2682
AclResult aclresult ;
@@ -2676,8 +2695,10 @@ LookupExplicitNamespace(const char *nspname)
2676
2695
*/
2677
2696
}
2678
2697
2679
- namespaceId = get_namespace_oid (nspname , false);
2680
-
2698
+ namespaceId = get_namespace_oid (nspname , missing_ok );
2699
+ if (missing_ok && !OidIsValid (namespaceId ))
2700
+ return InvalidOid ;
2701
+
2681
2702
aclresult = pg_namespace_aclcheck (namespaceId , GetUserId (), ACL_USAGE );
2682
2703
if (aclresult != ACLCHECK_OK )
2683
2704
aclcheck_error (aclresult , ACL_KIND_NAMESPACE ,
@@ -3248,7 +3269,9 @@ get_collation_oid(List *name, bool missing_ok)
3248
3269
if (schemaname )
3249
3270
{
3250
3271
/* use exact schema given */
3251
- namespaceId = LookupExplicitNamespace (schemaname );
3272
+ namespaceId = LookupExplicitNamespace (schemaname , missing_ok );
3273
+ if (missing_ok && !OidIsValid (namespaceId ))
3274
+ return InvalidOid ;
3252
3275
3253
3276
/* first try for encoding-specific entry, then any-encoding */
3254
3277
colloid = GetSysCacheOid3 (COLLNAMEENCNSP ,
@@ -3318,10 +3341,13 @@ get_conversion_oid(List *name, bool missing_ok)
3318
3341
if (schemaname )
3319
3342
{
3320
3343
/* use exact schema given */
3321
- namespaceId = LookupExplicitNamespace (schemaname );
3322
- conoid = GetSysCacheOid2 (CONNAMENSP ,
3323
- PointerGetDatum (conversion_name ),
3324
- ObjectIdGetDatum (namespaceId ));
3344
+ namespaceId = LookupExplicitNamespace (schemaname , missing_ok );
3345
+ if (missing_ok && !OidIsValid (namespaceId ))
3346
+ conoid = InvalidOid ;
3347
+ else
3348
+ conoid = GetSysCacheOid2 (CONNAMENSP ,
3349
+ PointerGetDatum (conversion_name ),
3350
+ ObjectIdGetDatum (namespaceId ));
3325
3351
}
3326
3352
else
3327
3353
{
0 commit comments