Usually add partition tables and clear partition tables. There are two simple functions: create or replace function create_table (table_name character varying, table_num integer) RETURNS void LANGUAGE plpgsql AS $ function $ declare
V_date char (8); v_tablename varchar (64 );
Begin for I in 0 .. table_num loop
V_date: = to_char (current_date + I, 'yyyymmdd'); v_tablename: = table_name | '_' | v_date;
Execute 'create table' | v_tablename | '(like' | table_name | 'including all) inherits ('| table_name | ')'; execute 'Grant select on' | v_tablename | 'to dwetl ';
End loop; end $ function $;
-- Delete the Partition Table create or replace function drop_table (table_name character varying, table_num integer) RETURNS void LANGUAGE plpgsql AS $ function $ declare
V_date char (8); v_tablename varchar (64 );
Begin for I in 0 .. table_num loop
V_date: = to_char (current_date + I, 'yyyymmdd'); v_tablename: = table_name | '_' | v_date;
Execute 'drop table' | v_tablename;
End loop; end $ function $;
-- Execute the FUNCTION select create_table ('table _ name', table_num); select drop_table ('table _ name', table_num); -- delete the FUNCTION drop FUNCTION create_table (table_name character varying, table_num integer); # enter the drop FUNCTION drop_table parameter (table_name character varying, table_num integer );