clean
This commit is contained in:
parent
ab96a07e70
commit
a487b12b38
@ -1,53 +1,53 @@
|
|||||||
WITH
|
WITH
|
||||||
--startign month
|
--startign month
|
||||||
startm AS (
|
startm AS (
|
||||||
SELECT 1 as m
|
SELECT 1 as m
|
||||||
)
|
)
|
||||||
,m AS (
|
,m AS (
|
||||||
SELECT
|
SELECT
|
||||||
g.s calendar_month
|
g.s calendar_month
|
||||||
,startm.m starting_month
|
,startm.m starting_month
|
||||||
,g.s + CASE WHEN g.s < startm.m THEN startm.m +1 ELSE -startm.m +1 END fisc_month
|
,g.s + CASE WHEN g.s < startm.m THEN startm.m +1 ELSE -startm.m +1 END fisc_month
|
||||||
FROM
|
FROM
|
||||||
generate_series(1,12,1) g(s)
|
generate_series(1,12,1) g(s)
|
||||||
CROSS JOIN startm
|
CROSS JOIN startm
|
||||||
)
|
)
|
||||||
--select * from m
|
--select * from m
|
||||||
INSERT INTO
|
INSERT INTO
|
||||||
evt.fspr
|
evt.fspr
|
||||||
SELECT
|
SELECT
|
||||||
--TO_CHAR(gs.d,'YYYY.MM.DD')::ltree t1
|
--TO_CHAR(gs.d,'YYYY.MM.DD')::ltree t1
|
||||||
(
|
(
|
||||||
--year
|
--year
|
||||||
to_char(extract(year from gs.d),'FM0000')
|
to_char(extract(year from gs.d),'FM0000')
|
||||||
--month
|
--month
|
||||||
||'.'||to_char(m.fisc_month,'FM00')
|
||'.'||to_char(m.fisc_month,'FM00')
|
||||||
)::ltree t2
|
)::ltree t2
|
||||||
,tstzrange(gs.d,gs.d + '1 month'::interval) r
|
,tstzrange(gs.d,gs.d + '1 month'::interval) r
|
||||||
FROM
|
FROM
|
||||||
generate_series('2018-01-01 00:00'::timestamptz,'2099-12-01 00:00'::timestamptz,'1 month') gs(d)
|
generate_series('2018-01-01 00:00'::timestamptz,'2099-12-01 00:00'::timestamptz,'1 month') gs(d)
|
||||||
INNER JOIN m ON
|
INNER JOIN m ON
|
||||||
m.calendar_month = extract(month from gs.d)
|
m.calendar_month = extract(month from gs.d)
|
||||||
ORDER BY
|
ORDER BY
|
||||||
gs.d ASC
|
gs.d ASC
|
||||||
/*
|
/*
|
||||||
INSERT INTO
|
INSERT INTO
|
||||||
evt.fspr
|
evt.fspr
|
||||||
SELECT
|
SELECT
|
||||||
--TO_CHAR(gs.d,'YYYY.MM.DD')::ltree t1
|
--TO_CHAR(gs.d,'YYYY.MM.DD')::ltree t1
|
||||||
(
|
(
|
||||||
--year
|
--year
|
||||||
to_char(extract(year from gs.d),'FM0000')
|
to_char(extract(year from gs.d),'FM0000')
|
||||||
--quarter
|
--quarter
|
||||||
||'.'||to_char(m.fq,'FM00')
|
||'.'||to_char(m.fq,'FM00')
|
||||||
--month
|
--month
|
||||||
||'.'||to_char(m.fm,'FM00')
|
||'.'||to_char(m.fm,'FM00')
|
||||||
--day
|
--day
|
||||||
||'.'||to_char(extract(day from gs.d),'FM00')
|
||'.'||to_char(extract(day from gs.d),'FM00')
|
||||||
)::ltree t2
|
)::ltree t2
|
||||||
,tstzrange(gs.d,gs.d + '1 month'::interval) r
|
,tstzrange(gs.d,gs.d + '1 month'::interval) r
|
||||||
FROM
|
FROM
|
||||||
generate_series('2018-01-01 00:00'::timestamptz,'2099-12-01 00:00'::timestamptz,'1 day') gs(d)
|
generate_series('2018-01-01 00:00'::timestamptz,'2099-12-01 00:00'::timestamptz,'1 day') gs(d)
|
||||||
INNER JOIN m ON
|
INNER JOIN m ON
|
||||||
m.cm = extract(month from gs.d)
|
m.cm = extract(month from gs.d)
|
||||||
*/
|
*/
|
@ -1,10 +1,10 @@
|
|||||||
------------------------fiscal periods------------------------
|
------------------------fiscal periods------------------------
|
||||||
CREATE TABLE evt.fspr (
|
CREATE TABLE evt.fspr (
|
||||||
id ltree
|
id ltree
|
||||||
,dur tstzrange
|
,dur tstzrange
|
||||||
)
|
)
|
||||||
|
|
||||||
COMMENT ON COLUMN evt.fspr.id IS 'fiscal period';
|
COMMENT ON COLUMN evt.fspr.id IS 'fiscal period';
|
||||||
COMMENT ON COLUMN evt.fspr.dur IS 'duration of period as timestamp range';
|
COMMENT ON COLUMN evt.fspr.dur IS 'duration of period as timestamp range';
|
||||||
|
|
||||||
CREATE INDEX id_gist ON evt.fspr USING GIST (id);
|
CREATE INDEX id_gist ON evt.fspr USING GIST (id);
|
||||||
|
@ -5,50 +5,6 @@ CREATE OR REPLACE FUNCTION evt.log_insert() RETURNS trigger
|
|||||||
$func$
|
$func$
|
||||||
BEGIN
|
BEGIN
|
||||||
WITH
|
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 extraction-------------------------------------------
|
||||||
full_ex AS (
|
full_ex AS (
|
||||||
SELECT
|
SELECT
|
||||||
|
78
test
78
test
@ -1,40 +1,40 @@
|
|||||||
insert into evt.bpr(bpr)
|
insert into evt.bpr(bpr)
|
||||||
SELECT
|
SELECT
|
||||||
$${
|
$${
|
||||||
"gl": {
|
"gl": {
|
||||||
"lines": [
|
"lines": [
|
||||||
{
|
{
|
||||||
"amount": 2.19,
|
"amount": 2.19,
|
||||||
"account": "h.food"
|
"account": "h.food"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"amount": -2.19,
|
"amount": -2.19,
|
||||||
"account": "h.dcard"
|
"account": "h.dcard"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"jpath": [
|
"jpath": [
|
||||||
[
|
[
|
||||||
"{item,0}",
|
"{item,0}",
|
||||||
"{header}"
|
"{header}"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"{item,0}",
|
"{item,0}",
|
||||||
"{header}"
|
"{header}"
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"item": [
|
"item": [
|
||||||
{
|
{
|
||||||
"item": "green olives",
|
"item": "green olives",
|
||||||
"amount": 2.19,
|
"amount": 2.19,
|
||||||
"reason": "food",
|
"reason": "food",
|
||||||
"account": "h.food"
|
"account": "h.food"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"header": {
|
"header": {
|
||||||
"entity": "home",
|
"entity": "home",
|
||||||
"module": "MHI",
|
"module": "MHI",
|
||||||
"offset": "h.dcard",
|
"offset": "h.dcard",
|
||||||
"transaction": "purchase"
|
"transaction": "purchase"
|
||||||
}
|
}
|
||||||
}$$::jsonb bpr
|
}$$::jsonb bpr
|
Loading…
Reference in New Issue
Block a user