Often add partitioned tables, and clean up partitioned tables, very simple 2 functions--Add partition table 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 partition table CREATE OR REPLACE FUNCTION drop_table (table_name character varying,table_num integer) RETURNS void LANGUAGE L 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 $;
--Executive Function Select Create_table (' table_name ', table_num); Select Drop_table (' table_name ', table_num); --Delete Functions drop function create_table (table_name character varying,table_num integer); #必须写上输入参数 Drop FUNCTION drop_table (table_name character varying,table_num integer);