Skip to content
Snippets Groups Projects
Commit e7c16d55 authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Added function for merging arrays for task #3892

parent dabe3ef3
No related branches found
No related tags found
No related merge requests found
Pipeline #1383 passed
-- This function returns an array adding some elements and removing others
-- It is used to update recursively groupread and groupwrite properties
CREATE OR REPLACE FUNCTION update_array(input_array VARCHAR[], elements_to_add VARCHAR[], elements_to_remove VARCHAR[]) RETURNS VARCHAR[] AS
$func$
SELECT array_agg(elements) FROM (
SELECT DISTINCT UNNEST(input_array)
UNION SELECT DISTINCT UNNEST(elements_to_add)
EXCEPT SELECT DISTINCT UNNEST(elements_to_remove)
) AS output_values(elements)
$func$ LANGUAGE sql;
SELECT update_array('{"group1","group2"}'::VARCHAR[],'{"group2","group3"}'::VARCHAR[],'{"group1"}'::VARCHAR[]) = '{"group2","group3"}' AS test_passed;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment