datajoint / datajoint-python

Relational data pipelines for the science lab
https://datajoint.com/docs
GNU Lesser General Public License v2.1
163 stars 83 forks source link

Tables whose primary keys have zero attributes #113

Open dimitri-yatsenko opened 9 years ago

dimitri-yatsenko commented 9 years ago

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.

dimitri-yatsenko commented 9 years ago

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.

dimitri-yatsenko commented 8 years ago

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.

dimitri-yatsenko commented 6 years ago

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.

austin-hilberg commented 5 years ago

Corresponding issue created for datajoint-matlab