I'm new to the realm of Redshift, but not databases themselves. I'm trying to figure out a way to programmatically re-issue grants in my redshift cluster. It was agreed upon early on that users that have been granted access to a schema will have select or dml access based on their job role and region. I'd like to do something similar to this, but I can't seem to get this to compile in my RS cluster. Cluster is v1.0.18228
CREATE OR REPLACE FUNCTION adminscripts.update_groups(p_schema varchar)
LANGUAGE plpgsql
VOLATILE
AS $function$
DECLARE
v_schema_sel_gro varchar(100) := p_schema||'_sel_group';
v_schema_dml_gro varchar(100) := p_schema||'_dml_group';
v_schema_adm_gro varchar(100) := p_schema||'_adm_group';
v_gro_exists int;
db VARCHAR(100);
endtime datetime;
SQL text;
unload_id INT;
unload_time timestamp;
BEGIN
select count(*) into v_gro_exists
from pg_group where groname = v_schema_sel_gro ;
IF v_gro_exists = 0 THEN
create group v_schema_sel_gro ;
ELSE
RAISE info 'SELECT Group already exits ';
END IF;
GRANT USAGE ON SCHEMA p_schema TO GROUP v_schema_sel_gro;
GRANT SELECT ON ALL TABLES IN SCHEMA p_schema TO GROUP v_schema_sel_gro;
ALTER DEFAULT PRIVILEGES IN SCHEMA p_schema GRANT SELECT ON TABLES TO GROUP v_schema_sel_gro;
END;
$function$
;
Any help would be fantastic with this! Thanks in advance.
Jeremy