forecast_api/route_sql/list_changes.sql
PhilRunninger b171b4d7ac More refactoring. Code is much DRY-er.
I removed a bunch of duplication by:
1. Moving `if (!where)` logic into the build_where function - sending
   the "No body was sent." message back in the HTTP response object.
2. Putting all file read operations into a dedicated function -
   process_route. This takes a callback function that handles the
   remaining logic of each route after successfully reading the SQL
   file.
2023-08-29 11:52:55 -04:00

32 lines
741 B
SQL

WITH
agg as (
SELECT
ol.doc->>'user' "user"
,quota_rep_descr
,to_char((ol.doc->>'stamp')::timestamptz,'Mon-DD HH24:MI:SS') stamp
,ol.doc->>'tag' tag
,ol.doc->>'message' "comment"
,jsonb_pretty(ol.doc) doc
,ol.id
,to_char(round(sum(value_usd),2),'$999,999,999D00') sales
from
rlarp.osm_log ol
inner join rlarp.osm_pool on
id = logid
WHERE
where_clause
AND tag NOT IN ('Initial Build','last price')
group BY
ol.doc->>'user'
,quota_rep_descr
,ol.doc->>'stamp'
,ol.doc->>'tag'
,ol.doc->>'comment'
,jsonb_pretty(ol.doc)
,ol.id
ORDER BY
ol.id desc
)
SELECT
jsonb_agg(row_to_json(agg)::jsonb ORDER BY agg.id desc) x from agg