-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🗃️ define a cdevents lake table to store incoming cdevents as json
- Loading branch information
Showing
5 changed files
with
204 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 0 additions & 15 deletions
15
.sqlx/query-098856a9e50709b6723e01b83ac91b44dfcc1eccb9978b4a51e2c80764252c0e.json
This file was deleted.
Oops, something went wrong.
15 changes: 15 additions & 0 deletions
15
.sqlx/query-17752ec6d8d06c32be0e722452a9390d13fe4488e4acc200a143122505ddefd9.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,22 @@ | ||
-- Add up migration script here | ||
CREATE TABLE IF NOT EXISTS events ( | ||
id serial PRIMARY KEY, | ||
timestamp timestamptz NOT NULL, | ||
raw jsonb NOT NULL | ||
CREATE TABLE IF NOT EXISTS cdevents_lake ( | ||
timestamp TIMESTAMP WITH TIME ZONE NOT NULL, | ||
payload JSONB NOT NULL | ||
); | ||
|
||
-- TODO switch to brin index when more data (see [Avoiding the Pitfalls of BRIN Indexes in Postgres](https://www.crunchydata.com/blog/avoiding-the-pitfalls-of-brin-indexes-in-postgres)) | ||
CREATE INDEX IF NOT EXISTS cdevents_lake_timestamp_idx ON cdevents_lake (timestamp); | ||
|
||
-- create a view based on fields in the json payload | ||
-- source: [Postgresql json column to view - Database Administrators Stack Exchange](https://dba.stackexchange.com/questions/151838/postgresql-json-column-to-view?newreg=ed0a9389843a45699bfb02559dd32038) | ||
-- DO $$ | ||
-- DECLARE l_keys text; | ||
-- BEGIN | ||
-- drop view if exists YOUR_VIEW_NAME cascade; | ||
|
||
-- select string_agg(distinct format('jerrayel ->> %L as %I',jkey, jkey), ', ') | ||
-- into l_keys | ||
-- from cdevents_lake, jsonb_array_elements(payload) as t(jerrayel), jsonb_object_keys(t.jerrayel) as a(jkey); | ||
|
||
-- execute 'create view cdevents_flatten as select '||l_keys||' from cdevents_lake, jsonb_array_elements(payload) as t(jerrayel)'; | ||
-- END$$; |