Create and delete a partition table in postgresql

Source: Internet
Author: User

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 );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.