The payload
type is a little different.
SELECT * FROM key_count('events', 'payload');
SELECT type,
jsonb_object_keys(event),
COUNT(*)
FROM events
GROUP BY type, jsonb_object_keys(event)
CREATE TABLE public_events (
public_event_id SERIAL PRIMARY KEY,
event_id INTEGER NOT NULL
REFERENCES events(event_id),
payload JSONB NOT NULL);
INSERT INTO public_events (event_id, payload)
SELECT event_id, payload FROM events WHERE type = 'PublicEvent';
Note that the foreign key points the other way!
SELECT * FROM key_count('public_events', 'payload');
ALTER TABLE public_events DROP COLUMN payload;
UPDATE events SET payload = NULL WHERE type = 'PublicEvent';