Forum Discussion
Data Model for User Activity Flow
Anonymous , We are going to use postgres db. For the relational database event if we store the events in a single table, i would like to know how we should establish relationships between these events. Any idea on this?
Hi, SanthiyaMallow
Given the variability in the sequence of events, your approach to include a 'previous_event_id' in your event tracking is a smart move. This self-referencing key allows you to maintain a chain of events regardless of their order. Here's a suggestion on how to structure your events table in your PostgreSQL database:
1. Events Table, this table should have columns for 'event_id', 'previous_event_id', 'event_type' (e.g., home screen, pickup event), 'user_id', 'timestamp', and any other relevant information about the event. The 'previous_event_id' column is crucial as it links each event to its predecessor, forming a linked list of sorts.
2. Establishing Relationships, in a relational database like PostgreSQL, relationships are typically established through foreign keys. However, since your scenario involves linking records within the same table, you've effectively created a self-referencing relationship. Ensure that 'event_id' is a primary key and that 'previous_event_id' is a foreign key that references 'event_id' within the same table.
In short, if you have a large amount of data, relational database design is a very complex thing, requiring professionals to conduct requirements analysis, entity-relationship model design, paradigm design, index design, data type selection, table design, normalization and denormalization, security design, etc., you need to combine with the actual needs to design the database.
Best Regards,
Yang
Community Support Team
If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!
How to get your questions answered quickly -- How to provide sample data in the Power BI Forum