Subtypes and status-dependent data: pure relational approach

12 points by squadette


pushcx

Very clever strategy, thanks for a clear writeup. I think I found two resources that may be what you're looking for?

This strategy appears in Joe Celko's 2012 book Trees and Hierarchies in Sql for Smarties chapter 10.2, starting page 205:

Another version of the same approach [to subclassing] uses a two-part key in the subclass tables where one column is a constant that tells you what the table contains. Let's use abbreviation codes for “in state”, “out of state”, and “foreign” students.

It also appears in his 2008 Thinking in Sets section 6.4.1 page 100. There's an equivalent example, but the explanation is a single sentence:

I then use a compound key (gtin, media_type) and a constraint in each subclass table to ensure that the media_type is locked and agrees with the Publications table.

I read these books years ago but definitely didn't remember this design. At first glance it looks like an excellent tool for modeling sum types in SQL databases.