CREATEORREPLACEFUNCTION skytf.create_table() RETURNSvoid LANGUAGE plpgsql AS $function$ declare v_date char(8); v_tablename varchar(64); begin for i in0..1500loop v_date :=to_char(current_date + i,'YYYYMMDD'); v_tablename := 'tbl_tmp_' || v_date; execute'create table ' || v_tablename || ' (like tbl_tmp including constraints including indexes including defaults) inherits (tbl_tmp)'; execute'grant select on skytf.' || v_tablename || ' to dwetl'; endloop; end $function$;