Merge branch 'schema_qualified'

This commit is contained in:
Daniele Varrazzo 2018-03-19 19:47:23 +00:00
commit 31d15a87e7
10 changed files with 44 additions and 51 deletions

View File

@ -16,30 +16,6 @@ CREATE FUNCTION repack.version_sql() RETURNS text AS
$$SELECT 'pg_repack REPACK_VERSION'::text$$
LANGUAGE SQL IMMUTABLE STRICT;
CREATE FUNCTION repack.pg_version(version_str text DEFAULT NULL) RETURNS integer
AS $$
-- Return the server version number in a format similar to PG_VERSION_NUM.
-- Call with no argument for the server version, pass an argument for testing
select (case
when array_length(tokens, 1) = 2 then
to_char(tokens[1], 'FM00') ||
'00' || to_char(tokens[2], 'FM00')
when array_length(tokens, 1) = 3 then
to_char(tokens[1], 'FM00') ||
to_char(tokens[2], 'FM00') ||
to_char(tokens[3], 'FM00')
else
-- This will raise an error which we can read
'unexpected version string: ' || coalesce($1, version())
end)::int
from (
select string_to_array(substring(
split_part(coalesce($1, version()), ' ', 2)
from '\d+\.\d+(?:\.\d+)?'), '.')::int[]
) as x (tokens);
$$
LANGUAGE SQL IMMUTABLE;
CREATE AGGREGATE repack.array_accum (
sfunc = array_append,
basetype = anyelement,

View File

@ -35,6 +35,7 @@
#include "storage/lmgr.h"
#include "utils/array.h"
#include "utils/builtins.h"
#include "utils/guc.h"
#include "utils/lsyscache.h"
#include "utils/rel.h"
#include "utils/relcache.h"
@ -353,31 +354,47 @@ get_relation_name(Oid relid)
{
Oid nsp = get_rel_namespace(relid);
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
* 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) || \
(PG_VERSION_NUM >= 90600 && PG_VERSION_NUM < 90608) || \
(PG_VERSION_NUM >= 90500 && PG_VERSION_NUM < 90512) || \
(PG_VERSION_NUM >= 90400 && PG_VERSION_NUM < 90417) || \
(PG_VERSION_NUM >= 90300 && PG_VERSION_NUM < 90322) || \
(PG_VERSION_NUM >= 90200 && PG_VERSION_NUM < 90300) || \
(PG_VERSION_NUM >= 90100 && PG_VERSION_NUM < 90200))
/* Qualify the name if not visible in search path */
if (RelationIsVisible(relid))
nspname = NULL;
if ((ver >= 100000 && ver < 100003) ||
(ver >= 90600 && ver < 90608) ||
(ver >= 90500 && ver < 90512) ||
(ver >= 90400 && ver < 90417) ||
(ver >= 90300 && ver < 90322) ||
(ver >= 90200 && ver < 90300) ||
(ver >= 90100 && ver < 90200))
{
/* Qualify the name if not visible in search path */
if (RelationIsVisible(relid))
nspname = NULL;
else
nspname = get_namespace_name(nsp);
}
else
nspname = get_namespace_name(nsp);
#else
/* Qualify the name */
if (OidIsValid(nsp))
nspname = get_namespace_name(nsp);
else
nspname = NULL;
#endif
{
/* Always qualify the name */
if (OidIsValid(nsp))
nspname = get_namespace_name(nsp);
else
nspname = NULL;
}
return quote_qualified_identifier(nspname, get_rel_name(relid));
}

View File

@ -12,7 +12,7 @@ select filename from (values
(100000, 100003, 'repack_2.out'),
(100003, 110000, 'repack_3.out')
) as x (min, max, filename)
where min <= repack.pg_version() and repack.pg_version() < max;
where current_setting('server_version_num')::int between min and max - 1;
filename
------------
repack.out

View File

@ -12,7 +12,7 @@ select filename from (values
(100000, 100003, 'repack_2.out'),
(100003, 110000, 'repack_3.out')
) as x (min, max, filename)
where min <= repack.pg_version() and repack.pg_version() < max;
where current_setting('server_version_num')::int between min and max - 1;
filename
--------------
repack_1.out

View File

@ -12,7 +12,7 @@ select filename from (values
(100000, 100003, 'repack_2.out'),
(100003, 110000, 'repack_3.out')
) as x (min, max, filename)
where min <= repack.pg_version() and repack.pg_version() < max;
where current_setting('server_version_num')::int between min and max - 1;
filename
--------------
repack_2.out

View File

@ -12,7 +12,7 @@ select filename from (values
(100000, 100003, 'repack_2.out'),
(100003, 110000, 'repack_3.out')
) as x (min, max, filename)
where min <= repack.pg_version() and repack.pg_version() < max;
where current_setting('server_version_num')::int between min and max - 1;
filename
--------------
repack_3.out

View File

@ -12,7 +12,7 @@ select filename from (values
(100000, 100003, 'repack_2.out'),
(100003, 110000, 'repack_3.out')
) as x (min, max, filename)
where min <= repack.pg_version() and repack.pg_version() < max;
where current_setting('server_version_num')::int between min and max - 1;
filename
--------------
repack_4.out

View File

@ -12,7 +12,7 @@ select filename from (values
(100000, 100003, 'repack_2.out'),
(100003, 110000, 'repack_3.out')
) as x (min, max, filename)
where min <= repack.pg_version() and repack.pg_version() < max;
where current_setting('server_version_num')::int between min and max - 1;
filename
--------------
repack_5.out

View File

@ -12,7 +12,7 @@ select filename from (values
(100000, 100003, 'repack_2.out'),
(100003, 110000, 'repack_3.out')
) as x (min, max, filename)
where min <= repack.pg_version() and repack.pg_version() < max;
where current_setting('server_version_num')::int between min and max - 1;
filename
--------------
repack_6.out

View File

@ -12,7 +12,7 @@ select filename from (values
(100000, 100003, 'repack_2.out'),
(100003, 110000, 'repack_3.out')
) as x (min, max, filename)
where min <= repack.pg_version() and repack.pg_version() < max;
where current_setting('server_version_num')::int between min and max - 1;
SET client_min_messages = warning;
--