Use the Postgres way to get the version number
Unsurprisingly, there was one.
This commit is contained in:
parent
2fd0eb050a
commit
07e944d9d1
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
--
|
||||
|
Loading…
x
Reference in New Issue
Block a user