W
W
wawa2018-02-28 14:54:00
PostgreSQL
wawa, 2018-02-28 14:54:00

Is a 1:1 relationship needed here instead of expanding the table?

There is a user table with quite standard fields and an updated_at field (well, that's how it should be).
In addition, I keep statistics for users in such a way that they can simply be added to the user table in new fields or separated into a separate user_stats table with a 1:1 relationship with user.
In the second case, I select a separate entity and, for example, add the updated_at field to user_stats, explicitly indicating that this is the statistics update time. Otherwise (in the case of one user table), I would have to specify the name of this field as stats_updated_at, while it is not clear which fields this stats_updated_at and just updated_at are responsible for updating.
In general, allocating a separate user_stats table seems more kosher, but you will have to put up with the user + user_stats join when making queries.
How are you doing?
Update 1:
Is it possible to somehow get out with the help of views / inheritance / other features of postgres by explicitly selecting two entities, while avoiding 1:1 and therefore a join?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Evgeny Kalibrov, 2018-02-28
@wawa

You should not avoid join, nothing bad will come of it, do it kosher.

#
#, 2018-02-28
@mindtester

What is "kosher"?
it seems like simplicity rules both in performance, and in maintainability, and in extensibility .. but definitely not complication out of the blue
Update 1: view definitely looks much kosher ... in every sense

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question