diff --git a/schema/suggested_data/periods.sql b/schema/suggested_data/periods.sql index 39553da..83acbd7 100644 --- a/schema/suggested_data/periods.sql +++ b/schema/suggested_data/periods.sql @@ -1,53 +1,53 @@ -WITH ---startign month -startm AS ( - SELECT 1 as m -) -,m AS ( - SELECT - g.s calendar_month - ,startm.m starting_month - ,g.s + CASE WHEN g.s < startm.m THEN startm.m +1 ELSE -startm.m +1 END fisc_month - FROM - generate_series(1,12,1) g(s) - CROSS JOIN startm -) ---select * from m -INSERT INTO - evt.fspr -SELECT - --TO_CHAR(gs.d,'YYYY.MM.DD')::ltree t1 - ( - --year - to_char(extract(year from gs.d),'FM0000') - --month - ||'.'||to_char(m.fisc_month,'FM00') - )::ltree t2 - ,tstzrange(gs.d,gs.d + '1 month'::interval) r -FROM - generate_series('2018-01-01 00:00'::timestamptz,'2099-12-01 00:00'::timestamptz,'1 month') gs(d) - INNER JOIN m ON - m.calendar_month = extract(month from gs.d) -ORDER BY - gs.d ASC -/* -INSERT INTO - evt.fspr -SELECT - --TO_CHAR(gs.d,'YYYY.MM.DD')::ltree t1 - ( - --year - to_char(extract(year from gs.d),'FM0000') - --quarter - ||'.'||to_char(m.fq,'FM00') - --month - ||'.'||to_char(m.fm,'FM00') - --day - ||'.'||to_char(extract(day from gs.d),'FM00') - )::ltree t2 - ,tstzrange(gs.d,gs.d + '1 month'::interval) r -FROM - generate_series('2018-01-01 00:00'::timestamptz,'2099-12-01 00:00'::timestamptz,'1 day') gs(d) - INNER JOIN m ON - m.cm = extract(month from gs.d) +WITH +--startign month +startm AS ( + SELECT 1 as m +) +,m AS ( + SELECT + g.s calendar_month + ,startm.m starting_month + ,g.s + CASE WHEN g.s < startm.m THEN startm.m +1 ELSE -startm.m +1 END fisc_month + FROM + generate_series(1,12,1) g(s) + CROSS JOIN startm +) +--select * from m +INSERT INTO + evt.fspr +SELECT + --TO_CHAR(gs.d,'YYYY.MM.DD')::ltree t1 + ( + --year + to_char(extract(year from gs.d),'FM0000') + --month + ||'.'||to_char(m.fisc_month,'FM00') + )::ltree t2 + ,tstzrange(gs.d,gs.d + '1 month'::interval) r +FROM + generate_series('2018-01-01 00:00'::timestamptz,'2099-12-01 00:00'::timestamptz,'1 month') gs(d) + INNER JOIN m ON + m.calendar_month = extract(month from gs.d) +ORDER BY + gs.d ASC +/* +INSERT INTO + evt.fspr +SELECT + --TO_CHAR(gs.d,'YYYY.MM.DD')::ltree t1 + ( + --year + to_char(extract(year from gs.d),'FM0000') + --quarter + ||'.'||to_char(m.fq,'FM00') + --month + ||'.'||to_char(m.fm,'FM00') + --day + ||'.'||to_char(extract(day from gs.d),'FM00') + )::ltree t2 + ,tstzrange(gs.d,gs.d + '1 month'::interval) r +FROM + generate_series('2018-01-01 00:00'::timestamptz,'2099-12-01 00:00'::timestamptz,'1 day') gs(d) + INNER JOIN m ON + m.cm = extract(month from gs.d) */ \ No newline at end of file diff --git a/schema/tables/fspr.sql b/schema/tables/fspr.sql index 967fafe..25238fe 100644 --- a/schema/tables/fspr.sql +++ b/schema/tables/fspr.sql @@ -1,10 +1,10 @@ -------------------------fiscal periods------------------------ -CREATE TABLE evt.fspr ( - id ltree - ,dur tstzrange -) - -COMMENT ON COLUMN evt.fspr.id IS 'fiscal period'; -COMMENT ON COLUMN evt.fspr.dur IS 'duration of period as timestamp range'; - -CREATE INDEX id_gist ON evt.fspr USING GIST (id); +------------------------fiscal periods------------------------ +CREATE TABLE evt.fspr ( + id ltree + ,dur tstzrange +) + +COMMENT ON COLUMN evt.fspr.id IS 'fiscal period'; +COMMENT ON COLUMN evt.fspr.dur IS 'duration of period as timestamp range'; + +CREATE INDEX id_gist ON evt.fspr USING GIST (id); diff --git a/schema/triggers/log_insert.sql b/schema/triggers/log_insert.sql index 021b56e..6e2ae61 100644 --- a/schema/triggers/log_insert.sql +++ b/schema/triggers/log_insert.sql @@ -5,50 +5,6 @@ CREATE OR REPLACE FUNCTION evt.log_insert() RETURNS trigger $func$ BEGIN WITH - /* - ins AS ( - SELECT - 1 id - ,$${ - "gl": { - "lines": [ - { - "amount": 2.19, - "account": "h.food" - }, - { - "amount": -2.19, - "account": "h.dcard" - } - ], - "jpath": [ - [ - "{item,0}", - "{header}" - ], - [ - "{item,0}", - "{header}" - ] - ] - }, - "item": [ - { - "item": "green olives", - "amount": 2.19, - "reason": "food", - "account": "h.food" - } - ], - "header": { - "entity": "home", - "module": "MHI", - "offset": "h.dcard", - "transaction": "purchase" - } -}$$::jsonb bpr - ), - */ ------------------------------------full extraction------------------------------------------- full_ex AS ( SELECT diff --git a/test b/test index 98c83d6..a1d47ef 100644 --- a/test +++ b/test @@ -1,40 +1,40 @@ -insert into evt.bpr(bpr) - SELECT -$${ - "gl": { - "lines": [ - { - "amount": 2.19, - "account": "h.food" - }, - { - "amount": -2.19, - "account": "h.dcard" - } - ], - "jpath": [ - [ - "{item,0}", - "{header}" - ], - [ - "{item,0}", - "{header}" - ] - ] - }, - "item": [ - { - "item": "green olives", - "amount": 2.19, - "reason": "food", - "account": "h.food" - } - ], - "header": { - "entity": "home", - "module": "MHI", - "offset": "h.dcard", - "transaction": "purchase" - } +insert into evt.bpr(bpr) + SELECT +$${ + "gl": { + "lines": [ + { + "amount": 2.19, + "account": "h.food" + }, + { + "amount": -2.19, + "account": "h.dcard" + } + ], + "jpath": [ + [ + "{item,0}", + "{header}" + ], + [ + "{item,0}", + "{header}" + ] + ] + }, + "item": [ + { + "item": "green olives", + "amount": 2.19, + "reason": "food", + "account": "h.food" + } + ], + "header": { + "entity": "home", + "module": "MHI", + "offset": "h.dcard", + "transaction": "purchase" + } }$$::jsonb bpr \ No newline at end of file