mirror of
https://github.com/postgres/postgres.git
synced 2025-08-28 18:48:04 +03:00
Introduce new extended routines for FDW and foreign server lookups
The cache lookup routines for foreign-data wrappers and foreign servers are extended with an extra argument to handle a set of flags. The only value which can be used now is to indicate if a missing object should result in an error or not, and are designed to be extensible on need. Those new routines are added into the existing set of user-visible FDW APIs and documented in consequence. They will be used for future patches to improve the SQL interface for object addresses. Author: Michael Paquier Reviewed-by: Álvaro Herrera Discussion: https://postgr.es/m/CAB7nPqSZxrSmdHK-rny7z8mi=EAFXJ5J-0RbzDw6aus=wB5azQ@mail.gmail.com
This commit is contained in:
@@ -33,6 +33,18 @@
|
||||
*/
|
||||
ForeignDataWrapper *
|
||||
GetForeignDataWrapper(Oid fdwid)
|
||||
{
|
||||
return GetForeignDataWrapperExtended(fdwid, 0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* GetForeignDataWrapperExtended - look up the foreign-data wrapper
|
||||
* by OID. If flags uses FDW_MISSING_OK, return NULL if the object cannot
|
||||
* be found instead of raising an error.
|
||||
*/
|
||||
ForeignDataWrapper *
|
||||
GetForeignDataWrapperExtended(Oid fdwid, bits16 flags)
|
||||
{
|
||||
Form_pg_foreign_data_wrapper fdwform;
|
||||
ForeignDataWrapper *fdw;
|
||||
@@ -43,7 +55,11 @@ GetForeignDataWrapper(Oid fdwid)
|
||||
tp = SearchSysCache1(FOREIGNDATAWRAPPEROID, ObjectIdGetDatum(fdwid));
|
||||
|
||||
if (!HeapTupleIsValid(tp))
|
||||
elog(ERROR, "cache lookup failed for foreign-data wrapper %u", fdwid);
|
||||
{
|
||||
if ((flags & FDW_MISSING_OK) == 0)
|
||||
elog(ERROR, "cache lookup failed for foreign-data wrapper %u", fdwid);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fdwform = (Form_pg_foreign_data_wrapper) GETSTRUCT(tp);
|
||||
|
||||
@@ -91,6 +107,18 @@ GetForeignDataWrapperByName(const char *fdwname, bool missing_ok)
|
||||
*/
|
||||
ForeignServer *
|
||||
GetForeignServer(Oid serverid)
|
||||
{
|
||||
return GetForeignServerExtended(serverid, 0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* GetForeignServerExtended - look up the foreign server definition. If
|
||||
* flags uses FSV_MISSING_OK, return NULL if the object cannot be found
|
||||
* instead of raising an error.
|
||||
*/
|
||||
ForeignServer *
|
||||
GetForeignServerExtended(Oid serverid, bits16 flags)
|
||||
{
|
||||
Form_pg_foreign_server serverform;
|
||||
ForeignServer *server;
|
||||
@@ -101,7 +129,11 @@ GetForeignServer(Oid serverid)
|
||||
tp = SearchSysCache1(FOREIGNSERVEROID, ObjectIdGetDatum(serverid));
|
||||
|
||||
if (!HeapTupleIsValid(tp))
|
||||
elog(ERROR, "cache lookup failed for foreign server %u", serverid);
|
||||
{
|
||||
if ((flags & FSV_MISSING_OK) == 0)
|
||||
elog(ERROR, "cache lookup failed for foreign server %u", serverid);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
serverform = (Form_pg_foreign_server) GETSTRUCT(tp);
|
||||
|
||||
|
Reference in New Issue
Block a user