A table defined as (this is simplified):
CREATE TABLE build_events (
build_id INTEGER, -- associated with the builds table (joins not important here)
event_id INTEGER, -- increases for every entry that is inserted, used in a subquent ORDER BY
payload TEXT. -- JSON payload
);
Within the payload
column is actually a JSON payload.
At the moment, I don't have the ability to convert it to a json
or jsonb
type.
The JSON payload, contains three fields time
(unix epoch), origin
(uuid), and (yet again) payload
(string).
An example entry,
{
"time": 1122233344,
"origin": "a1b2c3",
"payload": "some entry from a log line"
}
No calculation is done against these entries, but a SELECT * FROM build_events WHERE build_id = ? ORDER event_id
is done at some point.
The event_id
is used to order the entries (not time
), probably as simple optimization.
In the build_events
table,
there can be multiple entries for the same time
,
I'd like to group those (via string concatenation) into a single entry by the time
value in the payload.
For example, given a table with the following entries:
build_id=1,event_id=1,payload=`{"time":"1234", payload:"log line 1\n"}`
build_id=1,event_id=2,payload=`{"time":"1234", payload:"log line 2\n"}`
build_id=1,event_id=3,payload=`{"time":"1235", payload:"log line 3\n"}`
build_id=1,event_id=4,payload=`{"time":"1236", payload:"log line 4\n"}`
I'd like to squash them together to look like:
build_id=1,event_id=1,payload=`{"time":"1234", payload:"log line 1\nlog line 2\n"}`
build_id=1,event_id=3,payload=`{"time":"1235", payload:"log line 3\n"}`
build_id=1,event_id=4,payload=`{"time":"1236", payload:"log line 4\n"}`
Notice the payload on the first entry includes the concatonated string of payload
.
If you can live without
event_id
, this appears to work: