Environment: DataJoint version (0.12.9) on Ubuntu with MySQL 5.7

The concept of FreeTable is nice. Provide a dj.conn() object and full_table_name and a table you can manipulate is created, independent of modules, virtual modules and schemas.

However, the behavior of this table is not like other user tables. For example, if you restrict with two dictionaries that should have no overlapping results, a normal table would return an empty set. However, a FreeTable return the results from just the second dictionary.

For example:

FreeTable & {'exists': 1} & {'exists': 0}

should return an empty table because and entry can't be both 1 and 0 simultaneously.

However, in this case the table that is returned is equivalent to:

FreeTable & {'exists': 0}

(Also querying with {'exists': 1} in the second position returns FreeTable & {'exists': 1})

The following works as expected and returns a table with no results:

FreeTable & dj.AndList([{'exists': 1}, {'exists': 0}])

I believe the reason this happens is because FreeTable inherits from Table and not UserTable, where the metaclass properties take effect.

My question is, what is the purpose of FreeTable and why couldn't it have inherited its properties from UserTable so it could be more useful?

1

There are 1 best solutions below

0
On

The purpose of FreeTable is exactly as you described: to provide access to a table in the database without a corresponding class.

Consider the following code

q = dj.FreeTable(dj.conn(), '`ephys`.`session`')

For example, if the table ephys.session has the field exists, then you can restrict the query as

q & {'exists': 1}

This will restrict the query q to the rows where the field exists = 1. However, if the table contains no such field, then no restriction is applied.

What you probably saw in your code is that the table of interest has no field with the name exists. When DataJoint restricts a query by a dict, then the non-existing fields are ignored.