SpacetimeDB icon indicating copy to clipboard operation
SpacetimeDB copied to clipboard

Consider whether to allow unique constraints on the empty set of columns

Open kazimuth opened this issue 1 year ago • 1 comments

In database dependency theory, it is legal to have a unique constraint (a kind of functional dependency) on the empty set of columns.

This is equivalent to having a unique constraint on a column of type (). A table can store at most one value of type (), so a table with such a constraint can store at most one column.

This is actually a very useful feature: it lets you have "global state" tables with only one row. But this could be considered an antipattern. We should decide whether or not to support it.

If we do want to support it, this may require some extra work. Our unique constraints are implemented with indexes, and I'm not sure if we support indexing on no columns. But this would be a backwards-compatible change.

kazimuth avatar Dec 30 '24 21:12 kazimuth

Our unique constraints are implemented with indexes, and I'm not sure if we support indexing on no columns.

Currently, we do not.

Centril avatar Jan 03 '25 09:01 Centril