Choose schema name visibility from running server version
Guarantee the extension compiled on newer servers can be used on older ones.
This commit is contained in:
parent
07e944d9d1
commit
c62d865c18
39
lib/repack.c
39
lib/repack.c
@ -35,6 +35,7 @@
|
|||||||
#include "storage/lmgr.h"
|
#include "storage/lmgr.h"
|
||||||
#include "utils/array.h"
|
#include "utils/array.h"
|
||||||
#include "utils/builtins.h"
|
#include "utils/builtins.h"
|
||||||
|
#include "utils/guc.h"
|
||||||
#include "utils/lsyscache.h"
|
#include "utils/lsyscache.h"
|
||||||
#include "utils/rel.h"
|
#include "utils/rel.h"
|
||||||
#include "utils/relcache.h"
|
#include "utils/relcache.h"
|
||||||
@ -353,31 +354,47 @@ get_relation_name(Oid relid)
|
|||||||
{
|
{
|
||||||
Oid nsp = get_rel_namespace(relid);
|
Oid nsp = get_rel_namespace(relid);
|
||||||
char *nspname;
|
char *nspname;
|
||||||
|
char *strver;
|
||||||
|
int ver;
|
||||||
|
|
||||||
|
/* Get the version of the running server (PG_VERSION_NUM would return
|
||||||
|
* the version we compiled the extension with) */
|
||||||
|
strver = GetConfigOptionByName("server_version_num", NULL
|
||||||
|
#if PG_VERSION_NUM >= 90600
|
||||||
|
, false /* missing_ok */
|
||||||
|
#endif
|
||||||
|
);
|
||||||
|
|
||||||
|
ver = atoi(strver);
|
||||||
|
pfree(strver);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Relation names given by PostgreSQL core are always
|
* Relation names given by PostgreSQL core are always
|
||||||
* qualified since some minor releases. Note that this change
|
* qualified since some minor releases. Note that this change
|
||||||
* doesn't introduce to PostgreSQL 9.2 and 9.1 releases.
|
* wasn't introduced in PostgreSQL 9.2 and 9.1 releases.
|
||||||
*/
|
*/
|
||||||
#if ((PG_VERSION_NUM >= 100000 && PG_VERSION_NUM < 100003) || \
|
if ((ver >= 100000 && ver < 100003) ||
|
||||||
(PG_VERSION_NUM >= 90600 && PG_VERSION_NUM < 90608) || \
|
(ver >= 90600 && ver < 90608) ||
|
||||||
(PG_VERSION_NUM >= 90500 && PG_VERSION_NUM < 90512) || \
|
(ver >= 90500 && ver < 90512) ||
|
||||||
(PG_VERSION_NUM >= 90400 && PG_VERSION_NUM < 90417) || \
|
(ver >= 90400 && ver < 90417) ||
|
||||||
(PG_VERSION_NUM >= 90300 && PG_VERSION_NUM < 90322) || \
|
(ver >= 90300 && ver < 90322) ||
|
||||||
(PG_VERSION_NUM >= 90200 && PG_VERSION_NUM < 90300) || \
|
(ver >= 90200 && ver < 90300) ||
|
||||||
(PG_VERSION_NUM >= 90100 && PG_VERSION_NUM < 90200))
|
(ver >= 90100 && ver < 90200))
|
||||||
|
{
|
||||||
/* Qualify the name if not visible in search path */
|
/* Qualify the name if not visible in search path */
|
||||||
if (RelationIsVisible(relid))
|
if (RelationIsVisible(relid))
|
||||||
nspname = NULL;
|
nspname = NULL;
|
||||||
else
|
else
|
||||||
nspname = get_namespace_name(nsp);
|
nspname = get_namespace_name(nsp);
|
||||||
#else
|
}
|
||||||
/* Qualify the name */
|
else
|
||||||
|
{
|
||||||
|
/* Always qualify the name */
|
||||||
if (OidIsValid(nsp))
|
if (OidIsValid(nsp))
|
||||||
nspname = get_namespace_name(nsp);
|
nspname = get_namespace_name(nsp);
|
||||||
else
|
else
|
||||||
nspname = NULL;
|
nspname = NULL;
|
||||||
#endif
|
}
|
||||||
|
|
||||||
return quote_qualified_identifier(nspname, get_rel_name(relid));
|
return quote_qualified_identifier(nspname, get_rel_name(relid));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user