mirror of
https://codeberg.org/icewind/log-archiver.git
synced 2026-06-03 09:34:09 +02:00
function for de-normalization
This commit is contained in:
parent
56a3e3d823
commit
1d2eb86bcb
1 changed files with 18 additions and 1 deletions
17
schema.sql
17
schema.sql
|
|
@ -37,3 +37,20 @@ CREATE INDEX logs_raw_players_idx
|
|||
ON logs_raw USING GIN (extract_players(json));
|
||||
|
||||
-- usage: select id from logs_raw where extract_players(json) @> ARRAY['[U:1:64229260]'];
|
||||
|
||||
|
||||
-- convert a normalized steamid into the format used in the provided json
|
||||
|
||||
CREATE FUNCTION un_normalize_steam_id(steamid TEXT, log JSONB) RETURNS TEXT AS $$
|
||||
DECLARE
|
||||
player TEXT;
|
||||
BEGIN
|
||||
FOR player in SELECT jsonb_object_keys(log->'players')
|
||||
LOOP
|
||||
IF normalize_steam_id(player) = steamid THEN RETURN player; END IF;
|
||||
END LOOP;
|
||||
RETURN '';
|
||||
END; $$
|
||||
LANGUAGE PLPGSQL IMMUTABLE;
|
||||
|
||||
-- example: SELECT id, json->'players'->un_normalize_steam_id('[U:1:64229260]', json)->'drops' from logs_raw where extract_players(json) @> ARRAY['[U:1:64229260]'];
|
||||
Loading…
Add table
Add a link
Reference in a new issue