======================================================================================================================================================
-- ##. Sample Object Create
======================================================================================================================================================
-- #1. Create Partition 
CREATE TABLE om_falt_alm_dts (
    alm_id character varying(22) NOT NULL,
    evt_time timestamp without time zone NOT NULL,
    eqp_cl_lvl1_id character varying(6) NOT NULL,    
    alm_seq numeric,
    chg_hst_ctt character varying(200)
)PARTITION BY RANGE (evt_time)

CREATE TABLE om_falt_alm_dts_20220227 PARTITION OF om_falt_alm_dts FOR VALUES FROM ('2022-02-27 00:00:00') TO ('2022-02-28 00:00:00') PARTITION BY RANGE (evt_time);
CREATE TABLE om_falt_alm_dts_20220227_1 PARTITION OF om_falt_alm_dts_20220227 FOR VALUES FROM ('2022-02-27 01:00:00') TO ('2022-02-28 02:00:00') PARTITION BY RANGE (evt_time);
CREATE TABLE om_falt_alm_dts_20220227_1_1 PARTITION OF om_falt_alm_dts_20220227_1 FOR VALUES FROM ('2022-02-27 01:00:00') TO ('2022-02-28 01:30:00') ;

CREATE TABLE om_falt_alm_dts_20220228 PARTITION OF om_falt_alm_dts FOR VALUES FROM ('2022-02-28 00:00:00') TO ('2022-03-01 00:00:00') PARTITION BY RANGE (evt_time);
CREATE TABLE om_falt_alm_dts_20220228_1 PARTITION OF om_falt_alm_dts_20220228 FOR VALUES FROM ('2022-02-28 00:00:00') TO ('2022-02-28 12:00:00');
CREATE TABLE om_falt_alm_dts_20220228_2 PARTITION OF om_falt_alm_dts_20220228 FOR VALUES FROM ('2022-02-28 12:00:00') TO ('2022-03-01 00:00:00');

CREATE TABLE om_falt_alm_dts_20230521 PARTITION OF om_falt_alm_dts FOR VALUES FROM ('2023-05-21 00:00:00') TO ('2023-05-22 00:00:00') PARTITION BY RANGE (evt_time);
CREATE TABLE om_falt_alm_dts_20230521_1 PARTITION OF om_falt_alm_dts_20230521 FOR VALUES FROM ('2023-05-21 01:00:00') TO ('2023-05-21 02:00:00') PARTITION BY RANGE (evt_time);
CREATE TABLE om_falt_alm_dts_20230521_1_1 PARTITION OF om_falt_alm_dts_20230521_1 FOR VALUES FROM ('2023-05-21 01:00:00') TO ('2023-05-21 01:30:00');
CREATE TABLE om_falt_alm_dts_20230521_1_2 PARTITION OF om_falt_alm_dts_20230521_1 FOR VALUES FROM ('2023-05-21 01:30:00') TO ('2023-05-21 02:00:00');
======================================================================================================================================================
-- #2. Create Another Partition 
create table p_quarter_check(
    id int not null
  , dept varchar(10)
  , name varchar(20)
  , in_d date not null
  , etc text)
  partition by range(in_d) ;

create table in_p_q1 partition of p_quarter_check for values from ('2023-01-01') to ('2023-04-01') PARTITION BY range (in_d) ;
create table in_p_q2 partition of p_quarter_check for values from ('2023-04-01') to ('2023-07-01') PARTITION BY range (in_d) ;
create table in_p_q3 partition of p_quarter_check for values from ('2023-07-01') to ('2023-10-01') PARTITION BY range (in_d) ;
create table in_p_q4 partition of p_quarter_check for values from ('2023-10-01') to ('2024-01-01') PARTITION BY range (in_d) ;

create table in_p_y202301 partition of in_p_q1 for values from ('2023-01-01') to ('2023-02-01') ;
create table in_p_y202302 partition of in_p_q1 for values from ('2023-02-01') to ('2023-03-01') ;
create table in_p_y202303 partition of in_p_q1 for values from ('2023-03-01') to ('2023-04-01') ;

create table in_p_y202304 partition of in_p_q2 for values from ('2023-04-01') to ('2023-05-01') ;
create table in_p_y202305 partition of in_p_q2 for values from ('2023-05-01') to ('2023-06-01') ;
create table in_p_y202306 partition of in_p_q2 for values from ('2023-06-01') to ('2023-07-01') ;

create table in_p_y202307 partition of in_p_q3 for values from ('2023-07-01') to ('2023-08-01') ;
create table in_p_y202308 partition of in_p_q3 for values from ('2023-08-01') to ('2023-09-01') ;
create table in_p_y202309 partition of in_p_q3 for values from ('2023-09-01') to ('2023-10-01') ;

create table in_p_y202310 partition of in_p_q4 for values from ('2023-10-01') to ('2023-11-01') ; 
create table in_p_y202311 partition of in_p_q4 for values from ('2023-11-01') to ('2023-12-01') ;
create table in_p_y202312 partition of in_p_q4 for values from ('2023-12-01') to ('2024-01-01') ;
======================================================================================================================================================
--#3. Create Index 
CREATE INDEX parent_idx01 ON p_quarter_check(id) ;
CREATE INDEX child_idx02 ON in_p_q1(dept) ;
CREATE INDEX child_child_idx03 ON public.in_p_y202301(etc);
