datajoint/datajoint-python

Tables whose primary keys have zero attributes

Opened this issue · 4 comments

Currently datajoint prohibits creating tables with no attributes in the primary key. We can relax this prohibition.

If the primary key has no attributes, it can only have one value. Therefore, the relation can only contain one tuple. So it's good for relations that contain a single fact about the universe rather than a collection of similar facts. The relational algebra using such relations remains identical to what it is now. In particular, joining two relations with no primary key produces another relation with no primary key and one tuple.

Note that this is different from SQL's tables that don't have a primary key. SQL is not exactly relational and its tables can contain duplicate rows. SQL does not have the equivalent of a primary key with zero attributes as defined here.

As @eywalker suggested, one way to think about this topic is to imaging that all tables have an additional attribute _epsilon_ whose domain contains a single value _Omega_. Then a relation with an empty primary key actually has one attribute in the primary key with only one possible value. As such, this relation can contain only one tuple.

If the primary key is empty, the table can have only one row. It is accomplished by adding an invisible column, defined as

_  = 1 : tinyint   # universe 
---

to the primary key. It cannot be fetched or inserted or updated and is not shown in previews.

Corresponding issue created for datajoint-matlab