2024-10-21 14:16:11 -04:00
|
|
|
WITH
|
|
|
|
----------raw message content---------------
|
|
|
|
ext AS (
|
|
|
|
SELECT
|
|
|
|
-- t.filename
|
|
|
|
(t.mdate - ((EXTRACT(DOW FROM t.mdate) - 5 + 7) % 7) * INTERVAL '1 day')::date AS week_ending
|
|
|
|
,t.mdate
|
2024-10-21 15:43:36 -04:00
|
|
|
,message->>'rep' rep
|
2024-10-21 14:16:11 -04:00
|
|
|
,message->>'text' markdown
|
|
|
|
,to_char(row_number() OVER (partition by (t.mdate - ((EXTRACT(DOW FROM t.mdate) - 5 + 7) % 7) * INTERVAL '1 day')::date),'FM000') seq
|
|
|
|
FROM
|
|
|
|
rlarp.thirtysec t
|
|
|
|
ORDER BY
|
|
|
|
t.mdate DESC
|
|
|
|
)
|
|
|
|
----------create unqiue list of weeks-------
|
|
|
|
,wk AS (
|
|
|
|
SELECT
|
|
|
|
week_ending
|
|
|
|
,'# '||week_ending markdown
|
2024-10-21 15:51:26 -04:00
|
|
|
,to_char(row_number() OVER (ORDER BY week_ending DESC),'FM000') seq
|
2024-10-21 14:16:11 -04:00
|
|
|
FROM
|
|
|
|
ext
|
|
|
|
CROSS JOIN (VALUES ('A'),('B')) r (flag)
|
|
|
|
GROUP BY
|
|
|
|
week_ending
|
|
|
|
ORDER BY
|
|
|
|
week_ending ASC
|
|
|
|
)
|
|
|
|
,wkh AS (
|
|
|
|
SELECT
|
|
|
|
w.week_ending
|
|
|
|
,w.seq||'.'||'000' || '.' || r.flag seq
|
|
|
|
,CASE r.flag
|
|
|
|
WHEN 'A' THEN w.markdown
|
|
|
|
WHEN 'B' THEN ''
|
|
|
|
END markdown
|
|
|
|
FROM
|
|
|
|
wk w
|
|
|
|
CROSS JOIN (VALUES ('A'),('B')) r (flag)
|
|
|
|
)
|
|
|
|
--------level 2 message header----------
|
|
|
|
,msg AS (
|
|
|
|
SELECT
|
|
|
|
e.week_ending
|
|
|
|
,w.seq || '.' || e.seq || '.' || r.flag seq
|
|
|
|
,CASE r.flag
|
2024-10-21 15:44:51 -04:00
|
|
|
WHEN 'A' THEN '## [['|| e.rep ||']]'
|
2024-10-21 15:43:36 -04:00
|
|
|
WHEN 'B' THEN ''
|
|
|
|
WHEN 'C' THEN e.markdown
|
|
|
|
WHEN 'D' THEN ''
|
2024-10-21 14:16:11 -04:00
|
|
|
END markdown
|
|
|
|
-- ,r.flag
|
|
|
|
FROM
|
|
|
|
ext e
|
2024-10-21 15:43:36 -04:00
|
|
|
CROSS JOIN (VALUES ('A'),('B'),('C'),('D')) r (flag)
|
2024-10-21 14:16:11 -04:00
|
|
|
INNER JOIN wk w ON
|
|
|
|
w.week_ending = e.week_ending
|
|
|
|
)
|
|
|
|
,stack AS (
|
|
|
|
SELECT
|
|
|
|
week_ending
|
|
|
|
,seq
|
|
|
|
,markdown
|
|
|
|
FROM
|
|
|
|
msg
|
|
|
|
UNION ALL
|
|
|
|
SELECT
|
|
|
|
week_ending
|
|
|
|
,seq
|
|
|
|
,markdown
|
|
|
|
FROM
|
|
|
|
wkh
|
|
|
|
)
|
2024-10-21 15:44:51 -04:00
|
|
|
SELECT markdown FROM stack order by seq
|