Re:Choosing a Database Schema for Polymorphic Data (2024)
by ozgrakkurt on Wednesday July 09, 2025 @03:18AM
(#44507138)
You can have different tables for different data. You don’t have to put all in same table
[ Parent
| on HN ]
Re:Choosing a Database Schema for Polymorphic Data (2024)
by setr on Wednesday July 09, 2025 @09:55AM
(#44510085)
Only the first strategy shoves it into the same table? The fundamental problem is record A can have type X Y or Z, with each type having additional metadata. You could flatten the model and have a table for each type X Y Z and query them independently, and pay the cost of duplicate schema structure and having to ensure they’re always synchronized manually (including any dependent tables), or you pluck out the common core and run into the article’s problem
Re:Choosing a Database Schema for Polymorphic Data (2024)
by gm678 on Wednesday July 09, 2025 @10:57AM
(#44510799)
I think the article alludes to the difficulty of this solution by discussing the need for invariants to be upheld when an insured patient becomes uninsured or vice versa. Different tables for each 'subclass' could be an option, but if that can change later on, you now need to move patients between the insured_patient and uninsured_patient tables and make sure you don't have duplicates.