From f63163c3d111c57bad04ce1d4b55bda6e902a9ee Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Mon, 28 Oct 2024 08:49:08 -0400 Subject: [PATCH] commit: 2024-10-28 08:49:08 --- dump_new_lastweek.pg.sql | 81 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 dump_new_lastweek.pg.sql diff --git a/dump_new_lastweek.pg.sql b/dump_new_lastweek.pg.sql new file mode 100644 index 0000000..bd1a056 --- /dev/null +++ b/dump_new_lastweek.pg.sql @@ -0,0 +1,81 @@ +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 + ,message->>'rep' rep + ,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 + ,to_char(row_number() OVER (ORDER BY week_ending DESC),'FM000') seq + 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) + WHERE + w.week_ending = (select max(week_ending) from ext) +) +--------level 2 message header---------- +,msg AS ( + SELECT + e.week_ending + ,w.seq || '.' || e.seq || '.' || r.flag seq + ,CASE r.flag + WHEN 'A' THEN '## [['|| e.rep ||']] ' || e.week_ending + WHEN 'B' THEN '' + WHEN 'C' THEN e.markdown + WHEN 'D' THEN '' + END markdown + -- ,r.flag + FROM + ext e + CROSS JOIN (VALUES ('A'),('B'),('C'),('D')) r (flag) + INNER JOIN wk w ON + w.week_ending = e.week_ending + WHERE + e.week_ending = (select max(week_ending) from ext) +) +,stack AS ( + SELECT + week_ending + ,seq + ,markdown + FROM + msg + UNION ALL + SELECT + week_ending + ,seq + ,markdown + FROM + wkh +) +-- select * from msg +-- select * from ext where week_ending = (select max(week_ending) From ext) +SELECT markdown FROM stack order by seq