citus/src/test/regress/expected/distributed_functions_confl...

145 lines
3.6 KiB
Plaintext

-- This is designed to test worker_create_or_replace_object in PG11 with aggregates
-- Note in PG12 we use CREATE OR REPLACE AGGREGATE, thus the renaming does not occur
CREATE SCHEMA proc_conflict;
SELECT run_command_on_workers($$CREATE SCHEMA proc_conflict;$$);
run_command_on_workers
-------------------------------------
(localhost,57637,t,"CREATE SCHEMA")
(localhost,57638,t,"CREATE SCHEMA")
(2 rows)
\c - - - :worker_1_port
SET search_path TO proc_conflict;
CREATE FUNCTION existing_func(state int, i int) RETURNS int AS $$
BEGIN
RETURN state * 2 + i;
END;
$$ LANGUAGE plpgsql STRICT IMMUTABLE;
CREATE AGGREGATE existing_agg(int) (
SFUNC = existing_func,
STYPE = int
);
\c - - - :master_port
SET search_path TO proc_conflict;
CREATE FUNCTION existing_func(state int, i int) RETURNS int AS $$
BEGIN
RETURN state * i + i;
END;
$$ LANGUAGE plpgsql STRICT IMMUTABLE;
CREATE AGGREGATE existing_agg(int) (
SFUNC = existing_func,
STYPE = int
);
SELECT create_distributed_function('existing_agg(int)');
create_distributed_function
-----------------------------
(1 row)
\c - - - :worker_1_port
SET search_path TO proc_conflict;
WITH data (val) AS (
select 2
union all select 4
union all select 6
)
SELECT existing_agg(val) FROM data;
existing_agg
--------------
78
(1 row)
\c - - - :master_port
SET search_path TO proc_conflict;
WITH data (val) AS (
select 2
union all select 4
union all select 6
)
SELECT existing_agg(val) FROM data;
existing_agg
--------------
78
(1 row)
-- Now drop & recreate in order to make sure rename detects the existing renamed objects
-- hide cascades
SET client_min_messages TO error;
DROP AGGREGATE existing_agg(int) CASCADE;
DROP FUNCTION existing_func(int, int) CASCADE;
\c - - - :worker_1_port
SET search_path TO proc_conflict;
CREATE FUNCTION existing_func(state int, i int) RETURNS int AS $$
BEGIN
RETURN state * 3 + i;
END;
$$ LANGUAGE plpgsql STRICT IMMUTABLE;
CREATE AGGREGATE existing_agg(int) (
SFUNC = existing_func,
STYPE = int
);
\c - - - :master_port
SET search_path TO proc_conflict;
CREATE FUNCTION existing_func(state int, i int) RETURNS int AS $$
BEGIN
RETURN state * 5 + i;
END;
$$ LANGUAGE plpgsql STRICT IMMUTABLE;
CREATE AGGREGATE existing_agg(int) (
SFUNC = existing_func,
STYPE = int
);
SELECT create_distributed_function('existing_agg(int)');
create_distributed_function
-----------------------------
(1 row)
\c - - - :worker_1_port
SET search_path TO proc_conflict;
WITH data (val) AS (
select 2
union all select 4
union all select 6
)
SELECT existing_agg(val) FROM data;
existing_agg
--------------
76
(1 row)
\c - - - :master_port
SET search_path TO proc_conflict;
WITH data (val) AS (
select 2
union all select 4
union all select 6
)
SELECT existing_agg(val) FROM data;
existing_agg
--------------
76
(1 row)
-- now test worker_create_or_replace_object directly
CREATE FUNCTION existing_func2(state int, i int) RETURNS int AS $$
BEGIN
RETURN state + i;
END;
$$ LANGUAGE plpgsql STRICT IMMUTABLE;
SELECT worker_create_or_replace_object('CREATE AGGREGATE proc_conflict.existing_agg(integer) (STYPE = integer,SFUNC = proc_conflict.existing_func2)');
worker_create_or_replace_object
---------------------------------
t
(1 row)
SELECT worker_create_or_replace_object('CREATE AGGREGATE proc_conflict.existing_agg(integer) (STYPE = integer,SFUNC = proc_conflict.existing_func2)');
worker_create_or_replace_object
---------------------------------
f
(1 row)
-- hide cascades
SET client_min_messages TO error;
DROP SCHEMA proc_conflict CASCADE;